├── .vs
├── Fasterflect
│ └── v14
│ │ └── .suo
└── restore.dg
├── MyGet.bat
├── src
└── Fasterflect.Netstandard
│ ├── Emitter
│ ├── EmitHelper.cs
│ ├── ValueTypeHolder.cs
│ ├── ArrayGetEmitter.cs
│ ├── ArraySetEmitter.cs
│ ├── InvocationEmitter.cs
│ ├── MapCallInfo.cs
│ ├── BaseEmitter.cs
│ ├── CtorInvocationEmitter.cs
│ ├── MemberSetEmitter.cs
│ ├── MemberGetEmitter.cs
│ ├── MethodInvocationEmitter.cs
│ └── MapEmitter.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── Extensions
│ ├── Net35CompatibilityExtensions.cs
│ ├── Core
│ │ ├── ConstructorInfoExtensions.cs
│ │ ├── ArrayExtensions.cs
│ │ ├── ValueTypeExtensions.cs
│ │ ├── FieldInfoExtensions.cs
│ │ ├── ParameterInfoExtensions.cs
│ │ ├── PropertyInfoExtensions.cs
│ │ ├── AssemblyExtensions.cs
│ │ └── MethodInfoExtensions.cs
│ └── Services
│ │ ├── Probing
│ │ └── ConstructorMap.cs
│ │ ├── TryCallMethodExtensions.cs
│ │ └── XmlTransformerExtensions.cs
│ ├── Caching
│ └── CacheStrategy.cs
│ ├── Common
│ ├── Constants.cs
│ ├── FormatOptions.cs
│ ├── Utils.cs
│ └── Delegates.cs
│ ├── Fasterflect.Netstandard.csproj
│ └── DynamicReflection
│ ├── DynamicBuilder.cs
│ └── DynamicWrapper.cs
├── .hgignore
├── tests
└── Fasterflect.Netframework.Tests
│ ├── packages.config
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── SampleModel
│ ├── Generics
│ │ ├── Concrete.cs
│ │ ├── GenericBase.cs
│ │ └── AbstractGenericBase.cs
│ ├── People
│ │ ├── ISwimmable.cs
│ │ ├── Employee.cs
│ │ ├── Person.cs
│ │ └── PersonStruct.cs
│ └── Animals
│ │ ├── Interfaces
│ │ ├── IBite.cs
│ │ ├── ISlide.cs
│ │ └── ISwim.cs
│ │ ├── Attributes
│ │ ├── CarnivoreAttribute.cs
│ │ ├── CodeAttribute.cs
│ │ └── ZoneAttribute.cs
│ │ ├── Enumerations
│ │ ├── MovementCapabilities.cs
│ │ ├── Zone.cs
│ │ └── Climate.cs
│ │ ├── Mammal.cs
│ │ ├── Reptile.cs
│ │ ├── Giraffe.cs
│ │ ├── Zoo.cs
│ │ ├── Snake.cs
│ │ ├── Elephant.cs
│ │ ├── Animal.cs
│ │ └── Lion.cs
│ ├── Issues
│ ├── IssueList.cs
│ ├── AmbiguousMatchTest.cs
│ └── IssueList2.cs
│ ├── Invocation
│ ├── TestUtils.cs
│ ├── BaseInvocationTest.cs
│ ├── MemberTest.cs
│ ├── ArrayTest.cs
│ ├── IndexerTest.cs
│ ├── GenericTest.cs
│ ├── DelegateCacheTest.cs
│ └── DelegateTest.cs
│ ├── Common
│ ├── TestUtils.cs
│ └── BaseTest.cs
│ ├── Internal
│ └── FlagsTest.cs
│ ├── Services
│ ├── DynamicTest.cs
│ ├── XmlTransformerTest.cs
│ └── EventHandlerTest.cs
│ ├── Lookup
│ ├── AssemblyTest.cs
│ ├── TryGetSetTest.cs
│ ├── ParameterTest.cs
│ └── ConstructorTest.cs
│ └── Probing
│ ├── TryCallMethodTest.cs
│ ├── TypeConverterTest.cs
│ ├── TryCallMethodValuesOnlyTest.cs
│ └── MethodDispatcherTest.cs
├── NuGet.config
├── post-MyGet.ps1
└── Fasterflect.sln
/.vs/Fasterflect/v14/.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloKitty/fasterflect/HEAD/.vs/Fasterflect/v14/.suo
--------------------------------------------------------------------------------
/MyGet.bat:
--------------------------------------------------------------------------------
1 | %NUGET% restore Fasterflect.sln -NoCache -NonInteractive
2 | msbuild Fasterflect.sln /p:Configuration=Release
--------------------------------------------------------------------------------
/.vs/restore.dg:
--------------------------------------------------------------------------------
1 | #:C:\Users\Glader\Documents\GitHub\fasterflect\src\Fasterflect.Netstandard\Fasterflect.Netstandard.xproj
2 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Emitter/EmitHelper.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HelloKitty/fasterflect/HEAD/src/Fasterflect.Netstandard/Emitter/EmitHelper.cs
--------------------------------------------------------------------------------
/.hgignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 | *.ReSharper
3 | *.user
4 | bin
5 | obj
6 | Output
7 | Nuget/packages
8 | Nuget/fasterflect.*
9 | *.suo
10 | *.vs10x
11 | *.DotSettings
12 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/NuGet.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/post-MyGet.ps1:
--------------------------------------------------------------------------------
1 | ##Looks through the entire src directory and runs nuget pack with dependencies added on each csproj found
2 | ##foreach file in src/*
3 | foreach($f in Get-ChildItem ./src/)
4 | {
5 | ##foreach file in the src/*/ directory that ends with the .csproj format
6 | foreach($ff in (Get-ChildItem (Join-Path ./src/ $f.Name) | Where-Object { $_.Name.EndsWith(".csproj") }))
7 | {
8 | ##Add the project path + the csproj name and add the include referenced projects argument which will
9 | ##force nuget dependencies
10 | $projectArgs = "pack " + (Join-Path (Join-Path src/ $f.Name) $ff.Name)## + " -IncludeReferencedProjects"
11 | Start-Process dotnet $projectArgs -Wait
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle("Fasterflect.Netframework.Tests")]
6 | [assembly: AssemblyDescription("")]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany("Microsoft")]
9 | [assembly: AssemblyProduct("Fasterflect.Netframework.Tests")]
10 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: Guid("4ef5f3a5-53af-4291-aba0-0dd6dcb2e89b")]
17 |
18 | // [assembly: AssemblyVersion("1.0.*")]
19 | [assembly: AssemblyVersion("1.0.0.0")]
20 | [assembly: AssemblyFileVersion("1.0.0.0")]
21 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Generics/Concrete.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.SampleModel.Generics
22 | {
23 | internal class Concrete : GenericBase
24 | {
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Generics/GenericBase.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.SampleModel.Generics
22 | {
23 | internal class GenericBase : AbstractGenericBase
24 | {
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/People/ISwimmable.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.SampleModel.People
22 | {
23 | public interface ISwimmable
24 | {
25 | void Swim( double meters );
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyConfiguration("")]
9 | [assembly: AssemblyCompany("www.github.com/hellokitty")]
10 | [assembly: AssemblyProduct("Fasterflect")]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: InternalsVisibleTo("Fasterflect.Netframework.Tests")]
13 |
14 | // Setting ComVisible to false makes the types in this assembly not visible
15 | // to COM components. If you need to access a type in this assembly from
16 | // COM, set the ComVisible attribute to true on that type.
17 | [assembly: ComVisible(false)]
18 |
19 | // The following GUID is for the ID of the typelib if this project is exposed to COM
20 | [assembly: Guid("5c6966b7-610e-42d2-9661-c80c46392124")]
21 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Interfaces/IBite.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 |
23 | namespace FasterflectTest.SampleModel.Animals.Interfaces
24 | {
25 | internal interface IBite
26 | {
27 | bool Bite( Animal animal );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Generics/AbstractGenericBase.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.SampleModel.Generics
22 | {
23 | internal abstract class AbstractGenericBase
24 | {
25 | public virtual T Value { get; protected set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Interfaces/ISlide.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.SampleModel.Animals.Interfaces
22 | {
23 | internal interface ISlide
24 | {
25 | double SlideDistance { get; }
26 |
27 | void Move( double distance );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Interfaces/ISwim.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 |
23 | namespace FasterflectTest.SampleModel.Animals.Interfaces
24 | {
25 | internal interface ISwim
26 | {
27 | double SwimDistance { get; }
28 |
29 | void Move( double distance );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Attributes/CarnivoreAttribute.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 |
23 | namespace FasterflectTest.SampleModel.Animals.Attributes
24 | {
25 | [AttributeUsage(AttributeTargets.Class)]
26 | internal class CarnivoreAttribute : Attribute
27 | {
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Issues/IssueList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using Fasterflect;
4 | using NUnit.Framework;
5 |
6 | namespace FasterflectTest.Issues
7 | {
8 | [TestFixture]
9 | public class IssueList
10 | {
11 | [Test]
12 | public void Issue1()
13 | {
14 | Console.WriteLine("List 1: Add() without Fasterflect");
15 | var list1 = (ArrayList)typeof(ArrayList).CreateInstance();
16 | for (int i = 0; i < 10; i++)
17 | {
18 | list1.Add( i );
19 | }
20 |
21 | Console.WriteLine("List 1: Add() by Fasterflect");
22 | var list2 = typeof(ArrayList).CreateInstance();
23 | for (int i = 0; i < 10; i++)
24 | {
25 | list2.CallMethod("Add", i);
26 | }
27 | //var size = (int)list2.GetPropertyValue("Count");
28 | //for (int i = 0; i < size; i++)
29 | //{
30 | // Assert.AreEqual(i + 1, list2.GetIndexer(i));
31 | //}
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Enumerations/MovementCapabilities.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 |
23 | namespace FasterflectTest.SampleModel.Animals.Enumerations
24 | {
25 | [Flags]
26 | internal enum MovementCapabilities
27 | {
28 | Land = 1,
29 | Water = 2,
30 | Air = 4
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Enumerations/Zone.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 |
23 | namespace FasterflectTest.SampleModel.Animals.Enumerations
24 | {
25 | [Flags]
26 | internal enum Zone
27 | {
28 | Arctic = 1,
29 | Ocean = 1 << 1,
30 | Savannah = 1 << 2,
31 | Jungle = 1 << 3,
32 | Plains = 1 << 4,
33 | Woods = 1 << 5,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Extensions/Net35CompatibilityExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Reflection;
5 |
6 | namespace Fasterflect
7 | {
8 | ///
9 | /// Extensions class that help make net46 and netstandard code
10 | /// compatible with net35 without conditional compilation everywhere.
11 | ///
12 | public static class Net35CompatibilityExtensions
13 | {
14 | #if NET35
15 | ///
16 | /// A net35 extension that fills out GetTypeInfo for net35.
17 | ///
18 | ///
19 | /// Just the provided type.
20 | public static Type GetTypeInfo(this Type t)
21 | {
22 | return t;
23 | }
24 |
25 | ///
26 | /// A net35 extension that fills out GetMethodInfo for net35
27 | ///
28 | ///
29 | ///
30 | ///
31 | ///
32 | public static MethodInfo GetMethodInfo(this Func func)
33 | {
34 | return func.Method;
35 | }
36 | #endif
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Attributes/CodeAttribute.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 |
23 | namespace FasterflectTest.SampleModel.Animals.Attributes
24 | {
25 | [AttributeUsage(AttributeTargets.All)]
26 | internal class CodeAttribute : Attribute
27 | {
28 | public string Code { get; set; }
29 |
30 | public CodeAttribute( string code )
31 | {
32 | Code = code;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Enumerations/Climate.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using FasterflectTest.SampleModel.Animals.Attributes;
23 |
24 | namespace FasterflectTest.SampleModel.Animals.Enumerations
25 | {
26 | [Flags]
27 | [Code("Temperature")]
28 | internal enum Climate
29 | {
30 | [Code("Hot")]
31 | Hot = 1,
32 | [Code("Cold")]
33 | Cold = 2,
34 | [Code("Any")]
35 | Any = Hot | Cold
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Issues/AmbiguousMatchTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Linq;
4 | using Fasterflect;
5 | using NUnit.Framework;
6 |
7 | namespace FasterflectTest.Issues
8 | {
9 | [TestFixture]
10 | public class AmbiguousMatchTest
11 | {
12 | #region Sample Classes
13 | private class Foo
14 | {
15 | public object Property { get; set; }
16 | }
17 | private class Bar : Foo
18 | {
19 | public new string Property { get; set; }
20 | }
21 | #endregion
22 |
23 | [Test]
24 | public void Test_PropertyLookupWithNameAndEXHFlagShouldNotThrowAmbiguousMatchException()
25 | {
26 | var propertyInfo = typeof(Bar).Property( "Property", Flags.InstanceAnyVisibility | Flags.ExcludeHiddenMembers );
27 | Assert.IsNotNull( propertyInfo );
28 | Assert.AreEqual( typeof(Bar), propertyInfo.DeclaringType );
29 | }
30 |
31 | [Test]
32 | public void Test_PropertiesLookupWithNameAndEXHFlagShouldFindSingleResult()
33 | {
34 | var propertyInfo = typeof(Bar).Properties( Flags.InstanceAnyVisibility | Flags.ExcludeHiddenMembers, "Property" ).Single();
35 | Assert.IsNotNull( propertyInfo );
36 | Assert.AreEqual( typeof(Bar), propertyInfo.DeclaringType );
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Invocation/TestUtils.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.Invocation
22 | {
23 | public static class TestUtils
24 | {
25 | public static string FirstCharUpper( this string str )
26 | {
27 | if( string.IsNullOrEmpty( str ) )
28 | {
29 | return str;
30 | }
31 | return str.Substring( 0, 1 ).ToUpper() + str.Substring( 1 );
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Attributes/ZoneAttribute.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using FasterflectTest.SampleModel.Animals.Enumerations;
23 |
24 | namespace FasterflectTest.SampleModel.Animals.Attributes
25 | {
26 | [AttributeUsage(AttributeTargets.Class)]
27 | internal class ZoneAttribute : Attribute
28 | {
29 | public Zone Zone { get; set; }
30 |
31 | public ZoneAttribute( Zone zone )
32 | {
33 | Zone = zone;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Mammal.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using FasterflectTest.SampleModel.Animals.Enumerations;
22 |
23 | namespace FasterflectTest.SampleModel.Animals
24 | {
25 | internal abstract class Mammal : Animal
26 | {
27 | protected Mammal( Climate climateRequirements, MovementCapabilities movementCapabilities ) : base( climateRequirements, movementCapabilities )
28 | {
29 | }
30 |
31 | protected Mammal( int id, Climate climateRequirements, MovementCapabilities movementCapabilities ) : base( id, climateRequirements, movementCapabilities )
32 | {
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Common/TestUtils.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.Common
22 | {
23 | public static class TestUtils
24 | {
25 | public static string FirstCharUpper( this string str )
26 | {
27 | if( string.IsNullOrEmpty( str ) )
28 | {
29 | return str;
30 | }
31 | return str.Substring( 0, 1 ).ToUpper() + str.Substring( 1 );
32 | }
33 |
34 | public static string FirstCharLower( this string str )
35 | {
36 | if( string.IsNullOrEmpty( str ) )
37 | {
38 | return str;
39 | }
40 | return str.Substring( 0, 1 ).ToLower() + str.Substring( 1 );
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Reptile.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using FasterflectTest.SampleModel.Animals.Enumerations;
22 | using FasterflectTest.SampleModel.Animals.Interfaces;
23 |
24 | namespace FasterflectTest.SampleModel.Animals
25 | {
26 | internal abstract class Reptile : Animal, ISlide
27 | {
28 | protected Reptile( Climate climateRequirements, MovementCapabilities movementCapabilities ) : base( climateRequirements, movementCapabilities )
29 | {
30 | }
31 |
32 | protected Reptile( int id, Climate climateRequirements, MovementCapabilities movementCapabilities ) : base( id, climateRequirements, movementCapabilities )
33 | {
34 | }
35 |
36 | public virtual double SlideDistance { get; protected set; }
37 |
38 | public abstract void Move( double distance );
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Invocation/BaseInvocationTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using FasterflectTest.Common;
23 | using FasterflectTest.SampleModel.People;
24 |
25 | namespace FasterflectTest.Invocation
26 | {
27 | public abstract class BaseInvocationTest : BaseTest
28 | {
29 | protected static readonly Type EmployeeType = typeof(Employee);
30 | protected static readonly Type PersonType = typeof(Person);
31 | protected static readonly Type PersonStructType = typeof(PersonStruct);
32 |
33 | protected BaseInvocationTest() : base( new [] { PersonType, PersonStructType } )
34 | {
35 | }
36 |
37 | protected BaseInvocationTest(Type classType, Type structType)
38 | : base(new []{classType, structType})
39 | {
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Internal/FlagsTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using Fasterflect;
22 | using NUnit.Framework;
23 |
24 | namespace FasterflectTest.Internal
25 | {
26 | [TestFixture]
27 | public class FlagsTest
28 | {
29 | [Test]
30 | public void TestFlagsToString()
31 | {
32 | Assert.AreEqual( string.Empty, Flags.None.ToString() );
33 | Assert.AreEqual( "Public", Flags.Public.ToString() );
34 | Assert.AreEqual( "Instance", Flags.Instance.ToString() );
35 | Assert.AreEqual( "Public", (Flags.None | Flags.Public).ToString() );
36 | Assert.AreEqual( "Instance | Public", (Flags.Instance | Flags.Public).ToString() );
37 | Assert.AreEqual( "Instance | NonPublic | Public", (Flags.Instance | Flags.Public | Flags.NonPublic).ToString() );
38 | Assert.AreEqual( "Instance | NonPublic | Public", Flags.InstanceAnyVisibility.ToString() );
39 | }
40 | }
41 | }
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Caching/CacheStrategy.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace Fasterflect.Caching
22 | {
23 | ///
24 | /// An enumeration of the supported caching strategies.
25 | ///
26 | internal enum CacheStrategy
27 | {
28 | ///
29 | /// This value indicates that caching is disabled.
30 | ///
31 | None,
32 | ///
33 | /// This value indicates that caching is enabled, and that cached objects may be
34 | /// collected and released at will by the garbage collector. This is the default value.
35 | ///
36 | Temporary,
37 | ///
38 | /// This value indicates that caching is enabled, and that cached objects may not
39 | /// be garbage collected. The developer must manually ensure that objects are
40 | /// removed from the cache when they are no longer needed.
41 | ///
42 | Permanent
43 | }
44 | }
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Emitter/ValueTypeHolder.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | // Copyright 2010 Buu Nguyen, Morten Mertner
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
17 | #endregion
18 |
19 | using System;
20 |
21 | namespace Fasterflect.Emitter
22 | {
23 | ///
24 | /// A wrapper for value type. Must be used in order for Fasterflect to
25 | /// work with value type such as struct.
26 | ///
27 | internal class ValueTypeHolder
28 | {
29 | ///
30 | /// Creates a wrapper for value type. The wrapper
31 | /// can then be used with Fasterflect.
32 | ///
33 | /// The value type to be wrapped.
34 | /// Must be a derivative of ValueType.
35 | public ValueTypeHolder( object value )
36 | {
37 | Value = (ValueType) value;
38 | }
39 |
40 | ///
41 | /// The actual struct wrapped by this instance.
42 | ///
43 | public ValueType Value { get; set; }
44 | }
45 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/People/Employee.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | namespace FasterflectTest.SampleModel.People
22 | {
23 | public class Employee : Person, ISwimmable
24 | {
25 | private int employeeId;
26 |
27 | public int EmployeeId
28 | {
29 | get { return employeeId; }
30 | set { employeeId = value; }
31 | }
32 |
33 | public Employee[] Subordinates { get; private set; }
34 |
35 | public Employee( string name, int age ) : base( name, age )
36 | {
37 | employeeId = GetTotalPeopleCreated();
38 | }
39 |
40 | public Employee() : this( string.Empty, 0 )
41 | {
42 | }
43 |
44 | public Employee( Employee[] subordinates ) : this( string.Empty, 0 )
45 | {
46 | Subordinates = subordinates;
47 | }
48 |
49 | void ISwimmable.Swim( double meters )
50 | {
51 | metersTravelled += meters;
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Giraffe.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using FasterflectTest.SampleModel.Animals.Attributes;
22 | using FasterflectTest.SampleModel.Animals.Enumerations;
23 | using FasterflectTest.SampleModel.Animals.Interfaces;
24 |
25 | namespace FasterflectTest.SampleModel.Animals
26 | {
27 | [Zone(Zone.Savannah)]
28 | internal class Giraffe : Mammal, ISwim
29 | {
30 | public Giraffe( int id, Climate climateRequirements, MovementCapabilities movementCapabilities ) : base( id, climateRequirements, movementCapabilities )
31 | {
32 | }
33 |
34 | public Giraffe( Climate climateRequirements, MovementCapabilities movementCapabilities ) : base( climateRequirements, movementCapabilities )
35 | {
36 | }
37 |
38 | #region ISwim Members
39 | double ISwim.SwimDistance
40 | {
41 | get { throw new System.NotImplementedException(); }
42 | }
43 |
44 | void ISwim.Move( double distance )
45 | {
46 | throw new System.NotImplementedException();
47 | }
48 | #endregion
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Zoo.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System.Collections.Generic;
22 | using System.Collections.ObjectModel;
23 | using System.Linq;
24 |
25 | namespace FasterflectTest.SampleModel.Animals
26 | {
27 | internal sealed class Zoo : Collection
28 | {
29 | private const int FirstId = 1000;
30 | private static int nextId = FirstId;
31 | private readonly string name;
32 | private string alias;
33 |
34 | public Zoo( string name )
35 | {
36 | this.name = name;
37 | alias = name;
38 | }
39 |
40 | public IEnumerable Animals()
41 | {
42 | return this.Where( a => a is T ).Cast();
43 | }
44 |
45 | public void RegisterClass( string @class, string _section, string __name, int size )
46 | {
47 | }
48 |
49 | public string Name
50 | {
51 | get { return name; }
52 | }
53 | public string Alias
54 | {
55 | set { alias = value; }
56 | }
57 |
58 | public static int NextId
59 | {
60 | get { return ++nextId; }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Snake.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.ComponentModel;
23 | using FasterflectTest.SampleModel.Animals.Enumerations;
24 | using FasterflectTest.SampleModel.Animals.Interfaces;
25 |
26 | namespace FasterflectTest.SampleModel.Animals
27 | {
28 | internal class Snake : Reptile, ISwim, IBite
29 | {
30 | public Snake() : base( Climate.Hot, MovementCapabilities.Land )
31 | {
32 | HasDeadlyBite = true;
33 | }
34 |
35 | // regular member
36 | public bool HasDeadlyBite { get; private set; }
37 |
38 | // ISwim
39 | void ISwim.Move( double distance )
40 | {
41 | SwimDistance += distance;
42 | }
43 | public virtual double SwimDistance { get; private set; }
44 |
45 | // ISlide
46 | public override void Move( [DefaultValue(100d)] double distance )
47 | {
48 | SlideDistance += distance;
49 | }
50 | public override double SlideDistance { get; protected set; }
51 |
52 | // IBite
53 | public bool Bite( Animal animal )
54 | {
55 | return HasDeadlyBite;
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Common/Constants.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.Reflection;
23 | using Fasterflect.Emitter;
24 |
25 | namespace Fasterflect
26 | {
27 | internal static class Constants
28 | {
29 | public const string IndexerSetterName = "set_Item";
30 | public const string IndexerGetterName = "get_Item";
31 | public const string ArraySetterName = "[]=";
32 | public const string ArrayGetterName = "=[]";
33 | public static readonly Type ObjectType = typeof(object);
34 | public static readonly Type IntType = typeof(int);
35 | public static readonly Type StructType = typeof(ValueTypeHolder);
36 | public static readonly Type VoidType = typeof(void);
37 | public static readonly Type[] ArrayOfObjectType = new[] { typeof(object) };
38 | public static readonly object[] EmptyObjectArray = new object[0];
39 | public static readonly string[] EmptyStringArray = new string[0];
40 | public static readonly PropertyInfo[] EmptyPropertyInfoArray = new PropertyInfo[0];
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Invocation/MemberTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using Fasterflect;
23 | using NUnit.Framework;
24 |
25 | namespace FasterflectTest.Invocation
26 | {
27 | [TestFixture]
28 | public class MemberTest : BaseInvocationTest
29 | {
30 | [Test]
31 | public void TestAccessStaticMemberViaMemberInfo()
32 | {
33 | RunWith((Type type) =>
34 | {
35 | var memberInfo = type.Member("TotalPeopleCreated", Flags.StaticAnyVisibility);
36 | var totalPeopleCreated = (int)memberInfo.Get() + 1;
37 | memberInfo.Set(totalPeopleCreated);
38 | VerifyProperties(type, new { totalPeopleCreated });
39 | });
40 | }
41 |
42 | [Test]
43 | public void TestAccessInstanceMemberViaMemberInfo()
44 | {
45 | RunWith((object person) =>
46 | {
47 | var memberInfo = person.UnwrapIfWrapped().GetType().Member("Name");
48 | var name = (string)memberInfo.Get(person) + " updated";
49 | memberInfo.Set(person, name);
50 | VerifyProperties(person, new { name });
51 | });
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Extensions/Core/ConstructorInfoExtensions.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | // Copyright 2010 Buu Nguyen, Morten Mertner
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
17 | #endregion
18 |
19 | using System;
20 | using System.Reflection;
21 | using Fasterflect.Emitter;
22 |
23 | namespace Fasterflect
24 | {
25 | ///
26 | /// Extension methods for inspecting, invoking and working with constructors.
27 | ///
28 | public static class ConstructorInfoExtensions
29 | {
30 | ///
31 | /// Invokes the constructor with as arguments.
32 | /// Leave empty if the constructor has no argument.
33 | ///
34 | public static object CreateInstance( this ConstructorInfo ctorInfo, params object[] parameters )
35 | {
36 | return ctorInfo.DelegateForCreateInstance()( parameters );
37 | }
38 |
39 | ///
40 | /// Creates a delegate which can create instance based on the constructor .
41 | ///
42 | public static ConstructorInvoker DelegateForCreateInstance( this ConstructorInfo ctorInfo )
43 | {
44 | return (ConstructorInvoker) new CtorInvocationEmitter( ctorInfo, Flags.InstanceAnyVisibility ).GetDelegate();
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Services/DynamicTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using Fasterflect;
23 | using NUnit.Framework;
24 | using FasterflectTest.SampleModel.People;
25 |
26 | namespace FasterflectTest.Services
27 | {
28 | #if DOT_NET_4
29 | [TestFixture]
30 | public class DynamicTest
31 | {
32 | [Test]
33 | public void TestDynamicWrapper()
34 | {
35 | Person original = new Person( "Bruce Lee", 25 );
36 | dynamic wrapper = new DynamicWrapper( original );
37 | Assert.AreEqual( original.Name, wrapper.Name );
38 | Assert.AreEqual( original.Age, wrapper.Age );
39 | double distance;
40 | original.Walk( 10d, out distance );
41 | Assert.AreEqual( 10d, distance );
42 | wrapper.Walk( 10d, out distance );
43 | //Assert.AreEqual( 20d, distance );
44 | Assert.AreEqual( 20d, original.TryGetFieldValue( "metersTravelled" ) );
45 | }
46 |
47 | [Test]
48 | public void TestDynamicBuilder()
49 | {
50 | dynamic obj = new DynamicBuilder();
51 | obj.Value = 1;
52 | obj.GetMessage = new Func( () => "Value = " + obj.Value );
53 | // verify
54 | Assert.AreEqual( "Value = 1", obj.GetMessage() );
55 | // verify that we still work after updating member
56 | obj.Value = 5;
57 | Assert.AreEqual( "Value = 5", obj.GetMessage() );
58 | }
59 | }
60 | #endif
61 | }
62 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Common/FormatOptions.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | // Copyright 2010 Buu Nguyen, Morten Mertner
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
17 | #endregion
18 |
19 | using System;
20 |
21 | namespace Fasterflect
22 | {
23 | ///
24 | /// This enumeration allows you to customize the XML output of the ToXml extensions.
25 | ///
26 | [Flags]
27 | public enum FormatOptions
28 | {
29 | ///
30 | /// This option specifies the empty set of options and does not affect the output.
31 | ///
32 | None = 0,
33 | ///
34 | /// If this option is specified the generated XML will include an XML document header.
35 | ///
36 | AddHeader = 1,
37 | ///
38 | /// If this option is specified a line feed will be emitted after every XML element.
39 | ///
40 | NewLineAfterElement = 2,
41 | ///
42 | /// If this option is specified nested tags will be indented either 1 tab character
43 | /// (the default) or 4 space characters.
44 | ///
45 | Indent = 4,
46 | ///
47 | /// If this option is specified indentation will use spaces instead of tabs.
48 | ///
49 | UseSpaces = 8,
50 | ///
51 | /// This option, which combines AddHeader, NewLineAfterElement and Indent, provides the
52 | /// default set of options used.
53 | ///
54 | Default = AddHeader | NewLineAfterElement | Indent
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Elephant.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using FasterflectTest.SampleModel.Animals.Enumerations;
23 |
24 | namespace FasterflectTest.SampleModel.Animals
25 | {
26 | internal class Elephant : Mammal
27 | {
28 | #pragma warning disable 0169, 0649
29 | public int MethodInvoked { get; private set; }
30 | #pragma warning restore 0169, 0649
31 |
32 | #region Constructors
33 | public Elephant() : base( Climate.Hot, MovementCapabilities.Land )
34 | {
35 | }
36 | #endregion
37 |
38 | #region Methods
39 | public void Eat()
40 | {
41 | MethodInvoked = 1;
42 | }
43 | public void Eat( string food )
44 | {
45 | MethodInvoked = 2;
46 | }
47 | public void Eat( int count )
48 | {
49 | MethodInvoked = 3;
50 | }
51 | public void Eat( int count, string food )
52 | {
53 | MethodInvoked = 4;
54 | }
55 | public void Eat( double count, string food, bool isHay )
56 | {
57 | MethodInvoked = 5;
58 | }
59 |
60 | public void Roar( int count )
61 | {
62 | MethodInvoked = 10;
63 | }
64 | public void Roar( int count, int volume )
65 | {
66 | MethodInvoked = 11;
67 | }
68 | public void Accept( char c )
69 | {
70 | MethodInvoked = 12;
71 | }
72 | public void AcceptParams( params string[] args )
73 | {
74 | MethodInvoked = 13;
75 | }
76 | #endregion
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Issues/IssueList2.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using Fasterflect;
4 | using NUnit.Framework;
5 |
6 | namespace FasterflectTest.Issues
7 | {
8 | [TestFixture]
9 | public class IssueList2
10 | {
11 | [Test]
12 | public void ArrayListFailureDemo_Works()
13 | {
14 | var list = typeof(ArrayList).CreateInstance();
15 | var add_with_object = list.GetType().DelegateForCallMethod( "Add", typeof(object) );
16 | for( int i = 0; i < 10; i++ )
17 | {
18 | add_with_object( list, i );
19 | }
20 | var size = (int) list.GetPropertyValue( "Count" );
21 | Assert.AreEqual( 10, size );
22 | }
23 |
24 | // uncomment line 54 in LookupUtils to enable older code base behavior
25 | [Test]
26 | public void ArrayListFailureDemo_WorksButFailsWithOlderCodeBase()
27 | {
28 | var list = typeof(ArrayList).CreateInstance();
29 | var add_with_int = list.GetType().DelegateForCallMethod( "Add", typeof(int) );
30 | for (int i = 0; i < 10; i++)
31 | {
32 | add_with_int( list, i );
33 | }
34 | var size = (int)list.GetPropertyValue("Count");
35 | Assert.AreEqual( 10, size );
36 | }
37 |
38 | [Test]
39 | public void Issue1()
40 | {
41 | var list = typeof(ArrayList).CreateInstance();
42 | for (int i = 0; i < 10; i++)
43 | {
44 | list.CallMethod("Add", i);
45 | }
46 | var size = (int)list.GetPropertyValue("Count");
47 | Assert.AreEqual( 10, size );
48 | }
49 |
50 | class AClass
51 | {
52 | public AClass(object o)
53 | {
54 | }
55 | public int Add(object i)
56 | {
57 | Console.WriteLine( "object" );
58 | return 1;
59 | }
60 | public int Add(int i)
61 | {
62 | Console.WriteLine( "int" );
63 | return 1;
64 | }
65 | }
66 |
67 | [Test]
68 | public void Issue1a()
69 | {
70 | var list = typeof(AClass).CreateInstance(0);
71 | for (int i = 0; i < 10; i++)
72 | {
73 | list.CallMethod("Add", i);
74 | }
75 | }
76 |
77 | [Test]
78 | public void Issue2()
79 | {
80 | for( int i = 0; i < 10; i++ )
81 | {
82 | var obj = typeof(AClass).CreateInstance(i);
83 | Assert.IsNotNull(obj);
84 | }
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Emitter/ArrayGetEmitter.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | // Copyright 2010 Buu Nguyen, Morten Mertner
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
17 | #endregion
18 |
19 | using System;
20 | using System.Reflection;
21 | using System.Reflection.Emit;
22 |
23 | namespace Fasterflect.Emitter
24 | {
25 | internal class ArrayGetEmitter : BaseEmitter
26 | {
27 | public ArrayGetEmitter( Type targetType )
28 | : base(new CallInfo( targetType, null, Flags.InstanceAnyVisibility, MemberTypes.Method,
29 | Constants.ArrayGetterName, new[] { typeof(int) }, null, true ))
30 | {
31 | }
32 |
33 | protected internal override DynamicMethod CreateDynamicMethod()
34 | {
35 | return CreateDynamicMethod( Constants.ArrayGetterName, CallInfo.TargetType,
36 | Constants.ObjectType, new[] { Constants.ObjectType, Constants.IntType } );
37 | }
38 |
39 | protected internal override Delegate CreateDelegate()
40 | {
41 | Type elementType = CallInfo.TargetType.GetElementType();
42 | Generator.ldarg_0 // load array
43 | .castclass( CallInfo.TargetType ) // (T[])array
44 | .ldarg_1 // load index
45 | .ldelem( elementType ) // load array[index]
46 | .boxIfValueType( elementType ) // [box] return
47 | .ret();
48 | return Method.CreateDelegate( typeof(ArrayElementGetter) );
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Animal.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.ComponentModel;
23 | using System.Diagnostics;
24 | using FasterflectTest.SampleModel.Animals.Attributes;
25 | using FasterflectTest.SampleModel.Animals.Enumerations;
26 |
27 | namespace FasterflectTest.SampleModel.Animals
28 | {
29 | [DebuggerDisplay("ID={id}, Type={GetType()}")]
30 | internal abstract class Animal
31 | {
32 | private static int nextId = 1;
33 | [Code("ID")]
34 | private readonly int id;
35 | [DefaultValue(null)]
36 | private DateTime? birthDay;
37 |
38 | public int ID { get { return id; } }
39 | public DateTime? BirthDay { get { return birthDay; } set { birthDay = value; } }
40 | public Climate ClimateRequirements { get; private set; }
41 | [Code("Movement")]
42 | public MovementCapabilities MovementCapabilities { get; private set; }
43 |
44 | public static int LastID { get { return nextId-1; } }
45 |
46 | protected Animal( Climate climateRequirements, MovementCapabilities movementCapabilities )
47 | {
48 | id = nextId++;
49 | ClimateRequirements = climateRequirements;
50 | MovementCapabilities = movementCapabilities;
51 | }
52 |
53 | protected Animal( int id, Climate climateRequirements, MovementCapabilities movementCapabilities )
54 | {
55 | this.id = id;
56 | ClimateRequirements = climateRequirements;
57 | MovementCapabilities = movementCapabilities;
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Common/Utils.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2009 Buu Nguyen (http://www.buunguyen.net/blog)
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.Collections.Generic;
23 | using System.Diagnostics;
24 | using System.Reflection;
25 | using Fasterflect.Emitter;
26 |
27 | namespace Fasterflect
28 | {
29 | [DebuggerStepThrough]
30 | internal static class Utils
31 | {
32 | public static Type GetTypeAdjusted( this object obj )
33 | {
34 | var wrapper = obj as ValueTypeHolder;
35 | return wrapper == null
36 | ? obj is Type ? obj as Type : obj.GetType()
37 | : wrapper.Value.GetType();
38 | }
39 |
40 | public static Type[] ToTypeArray(this ParameterInfo[] parameters)
41 | {
42 | if (parameters.Length == 0)
43 | return Type.EmptyTypes;
44 | var types = new Type[parameters.Length];
45 | for (int i = 0; i < types.Length; i++)
46 | {
47 | types[i] = parameters[i].ParameterType;
48 | }
49 | return types;
50 | }
51 |
52 | public static Type[] ToTypeArray(this object[] objects)
53 | {
54 | if (objects.Length == 0)
55 | return Type.EmptyTypes;
56 | var types = new Type[objects.Length];
57 | for (int i = 0; i < types.Length; i++)
58 | {
59 | var obj = objects[ i ];
60 | types[i] = obj != null ? obj.GetType() : null;
61 | }
62 | return types;
63 | }
64 |
65 | public static void ForEach( this IEnumerable source, Action action )
66 | {
67 | foreach( T element in source )
68 | {
69 | action( element );
70 | }
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Emitter/ArraySetEmitter.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | // Copyright 2010 Buu Nguyen, Morten Mertner
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
17 | #endregion
18 |
19 | using System;
20 | using System.Reflection;
21 | using System.Reflection.Emit;
22 |
23 | namespace Fasterflect.Emitter
24 | {
25 | internal class ArraySetEmitter : BaseEmitter
26 | {
27 | public ArraySetEmitter( Type targetType )
28 | : base(new CallInfo(targetType, null, Flags.InstanceAnyVisibility, MemberTypes.Method, Constants.ArraySetterName,
29 | new[] { typeof(int), targetType.GetElementType() }, null, false))
30 | {
31 | }
32 |
33 | protected internal override DynamicMethod CreateDynamicMethod()
34 | {
35 | return CreateDynamicMethod( Constants.ArraySetterName, CallInfo.TargetType, null,
36 | new[] { Constants.ObjectType, Constants.IntType, Constants.ObjectType } );
37 | }
38 |
39 | protected internal override Delegate CreateDelegate()
40 | {
41 | Type elementType = CallInfo.TargetType.GetElementType();
42 | Generator.ldarg_0 // load array
43 | .castclass( CallInfo.TargetType ) // (T[])array
44 | .ldarg_1 // load index
45 | .ldarg_2 // load value
46 | .CastFromObject( elementType ) // (unbox | cast) value
47 | .stelem( elementType ) // array[index] = value
48 | .ret();
49 | return Method.CreateDelegate( typeof(ArrayElementSetter) );
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Fasterflect.Netstandard.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard1.5;net45;net35;net46;netstandard2.0
5 | Fasterflect.Netstandard
6 | Fasterflect.Netstandard
7 | false
8 | false
9 | false
10 | A port of Fasterflect to Netstandard.
11 | https://github.com/HelloKitty/fasterflect
12 | http://www.apache.org/licenses/LICENSE-2.0
13 | Buu Nguyen, Morten Mertner, Andrew Blakely
14 | Buu Nguyen, Morten Mertner, Andrew Blakely
15 | https://github.com/HelloKitty/fasterflect
16 | git
17 | fasterflect netstandard faster flect net standard netcore core port
18 |
19 |
20 |
21 | bin\Release\netstandard1.5\Fasterflect.Netstandard.xml
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Extensions/Services/Probing/ConstructorMap.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.Reflection;
23 |
24 | namespace Fasterflect.Probing
25 | {
26 | internal class ConstructorMap : MethodMap
27 | {
28 | private ConstructorInvoker invoker;
29 |
30 | public ConstructorMap( ConstructorInfo constructor, string[] paramNames, Type[] parameterTypes,
31 | object[] sampleParamValues, bool mustUseAllParameters )
32 | : base(constructor, paramNames, parameterTypes, sampleParamValues, mustUseAllParameters)
33 | {
34 | }
35 |
36 | #region UpdateMembers Private Helper Method
37 | private void UpdateMembers(object target, object[] row)
38 | {
39 | for( int i = 0; i < row.Length; i++ )
40 | {
41 | if( parameterReflectionMask[ i ] )
42 | {
43 | MemberInfo member = members[ i ];
44 | if( member != null )
45 | {
46 | object value = parameterTypeConvertMask[ i ] ? TypeConverter.Get( member.Type(), row[ i ] ) : row[ i ];
47 | member.Set( target, value );
48 | }
49 | }
50 | }
51 | }
52 | #endregion
53 |
54 | public override object Invoke( object[] row )
55 | {
56 | object[] methodParameters = isPerfectMatch ? row : PrepareParameters(row);
57 | object result = invoker.Invoke(methodParameters);
58 | if (!isPerfectMatch && AnySet(parameterReflectionMask))
59 | UpdateMembers(result, row);
60 | return result;
61 | }
62 |
63 | internal override void InitializeInvoker()
64 | {
65 | invoker = type.DelegateForCreateInstance( GetParamTypes() );
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/Fasterflect.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | VisualStudioVersion = 15.0.26730.8
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{D839B827-0ECA-4151-9A07-9161E209E23F}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{16D1FC09-2631-40EE-89CA-893073BCDA68}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fasterflect.Netstandard", "src\Fasterflect.Netstandard\Fasterflect.Netstandard.csproj", "{5C6966B7-610E-42D2-9661-C80C46392124}"
11 | EndProject
12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fasterflect.Netframework.Tests", "tests\Fasterflect.Netframework.Tests\Fasterflect.Netframework.Tests.csproj", "{4EF5F3A5-53AF-4291-ABA0-0DD6DCB2E89B}"
13 | EndProject
14 | Global
15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
16 | Debug|Any CPU = Debug|Any CPU
17 | Release|Any CPU = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {5C6966B7-610E-42D2-9661-C80C46392124}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {5C6966B7-610E-42D2-9661-C80C46392124}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {5C6966B7-610E-42D2-9661-C80C46392124}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {5C6966B7-610E-42D2-9661-C80C46392124}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {4EF5F3A5-53AF-4291-ABA0-0DD6DCB2E89B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {4EF5F3A5-53AF-4291-ABA0-0DD6DCB2E89B}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {4EF5F3A5-53AF-4291-ABA0-0DD6DCB2E89B}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {4EF5F3A5-53AF-4291-ABA0-0DD6DCB2E89B}.Release|Any CPU.Build.0 = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | GlobalSection(NestedProjects) = preSolution
33 | {5C6966B7-610E-42D2-9661-C80C46392124} = {D839B827-0ECA-4151-9A07-9161E209E23F}
34 | {4EF5F3A5-53AF-4291-ABA0-0DD6DCB2E89B} = {16D1FC09-2631-40EE-89CA-893073BCDA68}
35 | EndGlobalSection
36 | GlobalSection(ExtensibilityGlobals) = postSolution
37 | SolutionGuid = {A380C532-85D3-4F51-BB98-D8947FDF69D0}
38 | EndGlobalSection
39 | GlobalSection(TestCaseManagementSettings) = postSolution
40 | CategoryFile = Fasterflect.vsmdi
41 | EndGlobalSection
42 | EndGlobal
43 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/SampleModel/Animals/Lion.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.ComponentModel;
23 | using System.Reflection;
24 | using Fasterflect;
25 | using FasterflectTest.SampleModel.Animals.Attributes;
26 | using FasterflectTest.SampleModel.Animals.Enumerations;
27 |
28 | namespace FasterflectTest.SampleModel.Animals
29 | {
30 | [Zone(Zone.Savannah)]
31 | [Serializable]
32 | internal class Lion : Mammal
33 | {
34 | #pragma warning disable 0169, 0649
35 | [Code("Field")]
36 | private DateTime lastMealTime = DateTime.MinValue;
37 |
38 | [Code("ReadWrite Property")]
39 | [DefaultValue("Simba")]
40 | public string Name { get; private set; }
41 |
42 | [Code("ReadOnly Property")]
43 | public bool IsHungry { get { return DateTime.Now.AddHours( -12 ) > lastMealTime; } }
44 |
45 | public int ConstructorInstanceUsed { get; private set; }
46 | #pragma warning restore 0169, 0649
47 |
48 | #region Constructors
49 | public Lion() : this( typeof(Lion).Property( "Name" ).Attribute().Value.ToString() )
50 | {
51 | ConstructorInstanceUsed = 1;
52 | }
53 |
54 | public Lion( string name ) : base( Climate.Hot, MovementCapabilities.Land )
55 | {
56 | Name = name;
57 | ConstructorInstanceUsed = 2;
58 | }
59 |
60 | public Lion( int id ) : this( id, typeof(Lion).Property( "Name" ).Attribute().Value.ToString() )
61 | {
62 | ConstructorInstanceUsed = 3;
63 | }
64 |
65 | public Lion( int id, string name ) : base( id, Climate.Hot, MovementCapabilities.Land )
66 | {
67 | Name = name;
68 | ConstructorInstanceUsed = 4;
69 | }
70 | #endregion
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Invocation/ArrayTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using Fasterflect;
23 | using FasterflectTest.Common;
24 | using FasterflectTest.SampleModel.People;
25 | using NUnit.Framework;
26 |
27 | namespace FasterflectTest.Invocation
28 | {
29 | [TestFixture]
30 | public class ArrayTest : BaseInvocationTest
31 | {
32 | public ArrayTest() : base(typeof(Person[]), typeof(PersonStruct[])) {}
33 |
34 | [Test]
35 | public void TestConstructArrays()
36 | {
37 | RunWith((Type type) =>
38 | {
39 | var obj = type.CreateInstance(10);
40 | Assert.IsNotNull(obj);
41 | Assert.AreEqual(10, obj.GetPropertyValue("Length"));
42 | });
43 | }
44 |
45 | [Test]
46 | public void TestGetSetElements()
47 | {
48 | RunWith((Type type) =>
49 | {
50 | var array = type.CreateInstance(10);
51 | var instance = type.GetElementType().CreateInstance().WrapIfValueType();
52 | instance.SetFieldValue( "name", "John" );
53 | array.SetElement(1, instance.UnwrapIfWrapped());
54 | VerifyFields( array.GetElement( 1 ).WrapIfValueType(), new { name = "John" } );
55 | });
56 | }
57 |
58 | [Test]
59 | public void TestGetSetElementsOnIntArray()
60 | {
61 | var array = typeof(int[]).CreateInstance( 20 );
62 | array.SetElement( 5, 10 );
63 | Assert.AreEqual( 10, array.GetElement( 5 ) );
64 | }
65 |
66 | [Test]
67 | public void TestGetSetElementsOnArrayProperty()
68 | {
69 | var employee = EmployeeType.CreateInstance();
70 | employee.SetPropertyValue("Subordinates", new Employee[10]);
71 | var subordinates = employee.GetPropertyValue( "Subordinates" );
72 | subordinates.SetElement(5, employee);
73 | Assert.AreEqual(employee, subordinates.GetElement(5));
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/Extensions/Core/ArrayExtensions.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | // Copyright 2010 Buu Nguyen, Morten Mertner
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
17 | #endregion
18 |
19 | using System;
20 | using Fasterflect.Emitter;
21 |
22 | namespace Fasterflect
23 | {
24 | ///
25 | /// Extension methods for working with arrays.
26 | ///
27 | public static class ArrayExtensions
28 | {
29 | #region Array Access
30 | ///
31 | /// Sets to the element at position of .
32 | ///
33 | /// .
34 | public static object SetElement( this object array, int index, object value )
35 | {
36 | ((Array) array).SetValue( value, index );
37 | return array;
38 | }
39 |
40 | ///
41 | /// Gets the element at position of .
42 | ///
43 | public static object GetElement( this object array, int index )
44 | {
45 | return ((Array) array).GetValue( index );
46 | }
47 |
48 | ///
49 | /// Creates a delegate which can set element of .
50 | ///
51 | public static ArrayElementSetter DelegateForSetElement( this Type arrayType )
52 | {
53 | return (ArrayElementSetter) new ArraySetEmitter( arrayType ).GetDelegate();
54 | }
55 |
56 | ///
57 | /// Creates a delegate which can retrieve element of .
58 | ///
59 | public static ArrayElementGetter DelegateForGetElement( this Type arrayType )
60 | {
61 | return (ArrayElementGetter) new ArrayGetEmitter( arrayType ).GetDelegate();
62 | }
63 | #endregion
64 | }
65 | }
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Lookup/AssemblyTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.Collections.Generic;
23 | using System.Reflection;
24 | using Fasterflect;
25 | using NUnit.Framework;
26 |
27 | namespace FasterflectTest.Lookup
28 | {
29 | [TestFixture]
30 | public class AssemblyTest
31 | {
32 | #region Types()
33 | [Test]
34 | public void TestFindTypes()
35 | {
36 | Assembly assembly = Assembly.GetAssembly( typeof(int) );
37 | IList types = assembly.Types();
38 | Assert.IsNotNull( types );
39 | Assert.IsTrue( types.Count > 1000 );
40 | }
41 |
42 | [Test]
43 | public void TestFindTypesByEmptyNameListShouldReturnAllTypes()
44 | {
45 | Assembly assembly = Assembly.GetAssembly( typeof(int) );
46 | IList types = assembly.Types( new string[ 0 ] );
47 | Assert.IsNotNull( types );
48 | Assert.IsTrue( types.Count > 1000 );
49 |
50 | types = assembly.Types( null );
51 | Assert.IsNotNull( types );
52 | Assert.IsTrue( types.Count > 1000 );
53 | }
54 |
55 | [Test]
56 | public void TestFindTypesShouldReturnEmptyListIfNotFound()
57 | {
58 | Assembly assembly = Assembly.GetAssembly( typeof(int) );
59 | IList types = assembly.Types( "UrzgHafn" );
60 | Assert.IsNotNull( types );
61 | Assert.AreEqual( 0, types.Count );
62 | }
63 |
64 | [Test]
65 | public void TestFindTypesByName()
66 | {
67 | Assembly assembly = Assembly.GetAssembly( typeof(int) );
68 | IList types = assembly.Types( "Int32" );
69 | Assert.IsNotNull( types );
70 | Assert.AreEqual( 1, types.Count );
71 | }
72 |
73 | [Test]
74 | public void TestFindTypesByPartialName()
75 | {
76 | Assembly assembly = Assembly.GetAssembly( typeof(int) );
77 | IList types = assembly.Types( Flags.PartialNameMatch, "Engine" );
78 | Assert.IsNotNull( types );
79 | Assert.AreEqual( 2, types.Count );
80 | }
81 | #endregion
82 | }
83 | }
84 |
85 |
86 |
--------------------------------------------------------------------------------
/src/Fasterflect.Netstandard/DynamicReflection/DynamicBuilder.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | // Copyright 2010 Buu Nguyen, Morten Mertner
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
17 | #endregion
18 |
19 | #if DOT_NET_4
20 | using System;
21 | using System.Collections.Generic;
22 | using System.Dynamic;
23 |
24 | namespace Fasterflect
25 | {
26 | internal sealed class DynamicBuilder : DynamicObject
27 | {
28 | private readonly Dictionary members = new Dictionary ();
29 |
30 | #region DynamicObject Overrides
31 | ///
32 | /// Assigns the given value to the specified member, overwriting any previous definition if one existed.
33 | ///
34 | public override bool TrySetMember( SetMemberBinder binder, object value )
35 | {
36 | members[ binder.Name ] = value;
37 | return true;
38 | }
39 |
40 | ///
41 | /// Gets the value of the specified member.
42 | ///
43 | public override bool TryGetMember( GetMemberBinder binder, out object result )
44 | {
45 | if( members.ContainsKey( binder.Name ) )
46 | {
47 | result = members[ binder.Name ];
48 | return true;
49 | }
50 | return base.TryGetMember( binder, out result );
51 | }
52 |
53 | ///
54 | /// Invokes the specified member (if it is a delegate).
55 | ///
56 | public override bool TryInvokeMember( InvokeMemberBinder binder, object[] args, out object result )
57 | {
58 | object member;
59 | if( members.TryGetValue( binder.Name, out member ) )
60 | {
61 | var method = member as Delegate;
62 | if( method != null )
63 | {
64 | result = method.DynamicInvoke( args );
65 | return true;
66 | }
67 | }
68 | return base.TryInvokeMember( binder, args, out result );
69 | }
70 |
71 | ///
72 | /// Gets a list of all dynamically defined members.
73 | ///
74 | public override IEnumerable GetDynamicMemberNames()
75 | {
76 | return members.Keys;
77 | }
78 | #endregion
79 | }
80 | }
81 | #endif
82 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Services/XmlTransformerTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.Collections.Generic;
23 | using Fasterflect;
24 | using NUnit.Framework;
25 | using FasterflectTest.SampleModel.People;
26 |
27 | namespace FasterflectTest.Services
28 | {
29 | [TestFixture]
30 | public class XmlTransformerTest
31 | {
32 | #region ToXml
33 | //[Test]
34 | //public void TestToXml()
35 | //{
36 | // string xml = "{0}" +
37 | // "{0}{1}Bruce Lee{0}{1}25{0}{1}" +
38 | // "0{0}{0}";
39 | // string expected = string.Format( xml, Environment.NewLine, "\t" );
40 | // Person person = new Person( "Bruce Lee", 25 );
41 | // Assert.AreEqual( expected, person.ToXml() );
42 | //}
43 |
44 | [Test]
45 | public void TestToXml()
46 | {
47 | string xml = "{0}" +
48 | "{0}{1}{0}";
49 | string name = string.Format( "{1}Bruce Lee{0}", Environment.NewLine, "\t" );
50 | string age = string.Format( "{1}25{0}", Environment.NewLine, "\t" );
51 | string mt = string.Format( "{1}0{0}", Environment.NewLine, "\t" );
52 | var expected = new List();
53 | expected.Add( string.Format( xml, Environment.NewLine, name + age + mt ) );
54 | expected.Add( string.Format( xml, Environment.NewLine, name + mt + age ) );
55 | expected.Add( string.Format( xml, Environment.NewLine, age + name + mt ) );
56 | expected.Add( string.Format( xml, Environment.NewLine, age + mt + name ) );
57 | expected.Add( string.Format( xml, Environment.NewLine, mt + age + name ) );
58 | expected.Add( string.Format( xml, Environment.NewLine, mt + name + age ) );
59 | Person person = new Person( "Bruce Lee", 25 );
60 | Assert.IsTrue( expected.Contains( person.ToXml() ) );
61 | }
62 | #endregion
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Lookup/TryGetSetTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using Fasterflect;
22 | using FasterflectTest.SampleModel.Animals;
23 | using NUnit.Framework;
24 |
25 | namespace FasterflectTest.Lookup
26 | {
27 | [TestFixture]
28 | public class TryGetSetTest
29 | {
30 | [Test]
31 | public void TestTryGetSetField()
32 | {
33 | Lion lion = new Lion( 42, "Scar" );
34 | // tryget
35 | Assert.IsNull( lion.TryGetFieldValue( "name" ) );
36 | Assert.IsNull( lion.TryGetFieldValue( "ID" ) );
37 | Assert.AreEqual( 42, lion.TryGetFieldValue( "id" ) );
38 | Assert.AreEqual( 42, lion.TryGetFieldValue( "ID", Flags.InstanceAnyVisibility | Flags.IgnoreCase ) );
39 | // tryset
40 | Assert.IsFalse( lion.TrySetFieldValue( "missing", false ) );
41 | Assert.IsTrue( lion.TrySetFieldValue( "id", 43 ) );
42 | Assert.AreEqual( 43, lion.ID );
43 | }
44 |
45 | [Test]
46 | public void TestTryGetSetProperty()
47 | {
48 | Lion lion = new Lion( 42, "Scar" );
49 | // tryget
50 | Assert.IsNull( lion.TryGetPropertyValue( "missing" ) );
51 | Assert.AreEqual( 42, lion.TryGetPropertyValue( "ID" ) );
52 | Assert.AreEqual( "Scar", lion.TryGetPropertyValue( "Name" ) );
53 | // tryset
54 | Assert.IsFalse( lion.TrySetPropertyValue( "missing", false ) );
55 | Assert.IsTrue( lion.TrySetPropertyValue( "Name", "Simba" ) );
56 | Assert.AreEqual( "Simba", lion.Name );
57 | }
58 |
59 | [Test]
60 | public void TestTryGetSetMember()
61 | {
62 | Lion lion = new Lion( 42, "Scar" );
63 | // tryget
64 | Assert.IsNull( lion.TryGetValue( "missing" ) );
65 | Assert.AreEqual( 42, lion.TryGetValue( "id" ) );
66 | Assert.AreEqual( "Scar", lion.TryGetValue( "Name" ) );
67 | // tryset
68 | Assert.IsFalse( lion.TrySetValue( "missing", false ) );
69 | Assert.IsTrue( lion.TrySetValue( "id", 43 ) );
70 | Assert.AreEqual( 43, lion.ID );
71 | Assert.IsTrue( lion.TrySetValue( "ID", 44, Flags.InstanceAnyVisibility | Flags.IgnoreCase ) );
72 | Assert.IsTrue( lion.TrySetValue( "Name", "Simba" ) );
73 | Assert.AreEqual( 44, lion.ID );
74 | Assert.AreEqual( "Simba", lion.Name );
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/tests/Fasterflect.Netframework.Tests/Common/BaseTest.cs:
--------------------------------------------------------------------------------
1 | #region License
2 |
3 | // Copyright 2010 Buu Nguyen, Morten Mertner
4 | //
5 | // Licensed under the Apache License, Version 2.0 (the "License");
6 | // you may not use this file except in compliance with the License.
7 | // You may obtain a copy of the License at
8 | //
9 | // http://www.apache.org/licenses/LICENSE-2.0
10 | //
11 | // Unless required by applicable law or agreed to in writing, software
12 | // distributed under the License is distributed on an "AS IS" BASIS,
13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | // See the License for the specific language governing permissions and
15 | // limitations under the License.
16 | //
17 | // The latest version of this file can be found at http://fasterflect.codeplex.com/
18 |
19 | #endregion
20 |
21 | using System;
22 | using System.Linq;
23 | using Fasterflect;
24 | using NUnit.Framework;
25 |
26 | namespace FasterflectTest.Common
27 | {
28 | public abstract class BaseTest
29 | {
30 | protected readonly Type[] Types;
31 |
32 | protected BaseTest( Type[] types )
33 | {
34 | Types = types;
35 | }
36 |
37 | protected static void VerifyProperties( Type type, object sample )
38 | {
39 | var properties = sample.GetType().Properties();
40 | properties.ForEach( propInfo => Assert.AreEqual( propInfo.Get( sample ),
41 | type.GetPropertyValue( propInfo.Name.FirstCharUpper() ) ) );
42 | }
43 |
44 | protected static void VerifyProperties( object obj, object sample )
45 | {
46 | var properties = sample.GetType().Properties();
47 | properties.ForEach( propInfo => Assert.AreEqual( propInfo.Get( sample ),
48 | obj.GetPropertyValue( propInfo.Name.FirstCharUpper() ) ) );
49 | }
50 |
51 | protected static void VerifyFields( Type type, object sample )
52 | {
53 | var properties = sample.GetType().Properties();
54 | properties.ForEach( propInfo => Assert.AreEqual( propInfo.Get( sample ), type.GetFieldValue( propInfo.Name.FirstCharLower() ) ) );
55 | }
56 |
57 | protected static void VerifyFields( object obj, object sample )
58 | {
59 | var properties = sample.GetType().Properties();
60 | properties.ForEach( propInfo => Assert.AreEqual( propInfo.Get( sample ), obj.GetFieldValue( propInfo.Name.FirstCharLower() ) ) );
61 | }
62 |
63 | protected void RunWith( Action assertionAction )
64 | {
65 | Types.ForEach( assertionAction );
66 | }
67 |
68 | protected void RunWith( Action