public void Can_GetHashKeys() { stringMap.Each(x => Redis.SetEntryInHash(HashId, x.Key, x.Value)); var expectedKeys = stringMap.Map(x => x.Key); var hashKeys = Redis.GetHashKeys(HashId); Assert.That(hashKeys, Is.EquivalentTo(expectedKeys)); }
public async Task Can_GetHashKeys() { foreach (var x in stringMap) { await RedisAsync.SetEntryInHashAsync(HashId, x.Key, x.Value); } var expectedKeys = stringMap.Map(x => x.Key); var hashKeys = await RedisAsync.GetHashKeysAsync(HashId); Assert.That(hashKeys, Is.EquivalentTo(expectedKeys)); }
static void Map( this Dictionary <InstanceID, InstanceID> map, SegmentRecord segmentData, ushort nodeID, ushort targetSegmentID) { if (segmentData.StartNodeID == nodeID) { map.Map(segmentData, nodeID, true, targetSegmentID); } else if (segmentData.EndNodeID == nodeID) { map.Map(segmentData, nodeID, false, targetSegmentID); } }
public void DictionaryBaseTest() { var map = MapFactory.CreateMapRule <InnType, OutType2>(); //Adding mapping rule for field that does not match on name. map.GetRule <InnType, OutType2>() .Add(type => type.DesimalValue, type => type.DesimalValue1, BasicTypes.Convertable); var target = new Dictionary <int, InnType> { { 1, new InnType { DateTimeValue = DateTime.Now, MyInts = new List <int>(), StringValue = "test1", DesimalValue = 1 } }, { 2, new InnType { DateTimeValue = DateTime.Now, MyInts = new List <int>(), StringValue = "test1", DesimalValue = 2 } } }; var result = target.Map <int, InnType>().To <string, OutType2>(map); Assert.AreEqual(2, result.Count); }
public object Get(Reset request) { //Uncomment if you want this feature //throw new NotSupportedException("Disabling for Demo site. Based on the XSS attacks I know it will only be a matter of time before someone pulls the trigger."); var questionsd = new Dictionary <string, string>(RestQuestions); JavascriptQuestions.ForEach(questionsd.Add); var questions = new List <Question>(); questions.AddRange(RestQuestions.Map(kvp => ToQuestion(kvp.Key, kvp.Value, new List <string> { "rest", "http" }))); questions.AddRange(JavascriptQuestions.Map(kvp => ToQuestion(kvp.Key, kvp.Value, new List <string> { "javascript", "jquery" }))); var mythz = Repository.GetOrCreateUser(new User { DisplayName = "mythz" }); questions.ForEach(q => q.UserId = mythz.Id); questions.ForEach(q => Repository.StoreQuestion(q)); return(new ResetResponse()); }
static void Main(string[] args) { List <int> ls = new List <int>() { 1, 2, 3, 4, 5 }; Predicate <int> isEven = (i) => i % 2 == 0; Console.WriteLine(ls.ToOption <int>().LookUp <int>(1)); Console.WriteLine(ls.ToOption().LookUp <int>(isEven)); Dictionary <int, string> dict = new Dictionary <int, string>(); dict.Add(0, "2"); dict.Add(1, "0"); var newDict = dict.Map((str) => { return(int.Parse(str) + 3); }); int x = 0; newDict.TryGetValue(0, out x); Console.WriteLine(x); Console.ReadLine(); }
// Todo: Can we support DV2s? public int[] AddMany(DoubleLineSegment2 edgeSegment, IntVector2[] points) { Interlocked.Increment(ref AddManyInvocationCount); // return points.Map(p => 0); var segmentSeeingWaypoints = landPolyNode.ComputeSegmentSeeingWaypoints(edgeSegment); // It's safe to assume <some> point in points will be new, so preprocess which segments are betwen us and other edge segments var barriers = landPolyNode.FindContourAndChildHoleBarriers(); Dictionary <DoubleLineSegment2, IntLineSegment2[]> barriersBySegment = indicesBySegment.Map((s, _) => { Interlocked.Increment(ref AddManyConvexHullsComputed); var hull = GeometryOperations.ConvexHull4(s.First, s.Second, edgeSegment.First, edgeSegment.Second); return(barriers.Where(b => { var barrierDv2 = new DoubleLineSegment2(b.First.ToDoubleVector2(), b.Second.ToDoubleVector2()); return GeometryOperations.SegmentIntersectsConvexPolygonInterior(barrierDv2, hull); }).ToArray()); }); return(indicesBySegment[edgeSegment] = points.Map(p => { if (TryAdd(p, out var cpi)) { Interlocked.Increment(ref CrossoverPointsAdded); segmentByCrossoverPoint[p] = edgeSegment; } return cpi; })); bool TryAdd(IntVector2 crossoverPoint, out int crossoverPointIndex) { if (!crossoverPoints.TryAdd(crossoverPoint, out crossoverPointIndex)) { return(false); } var(visibleWaypointLinks, visibleWaypointLinksLength, optimalLinkToWaypoints, optimalLinkToCrossovers) = FindOptimalLinksToCrossovers(crossoverPoint, segmentSeeingWaypoints, barriersBySegment); // visibleWaypointLinksByCrossoverPointIndex.Add(visibleWaypointLinks); optimalLinkToWaypointsByCrossoverPointIndex.Add(optimalLinkToWaypoints); optimalLinkToOtherCrossoversByCrossoverPointIndex.Add(optimalLinkToCrossovers); Trace.Assert(optimalLinkToOtherCrossoversByCrossoverPointIndex.Count == optimalLinkToCrossovers.Count); for (var otherCpi = 0; otherCpi < crossoverPoints.Count - 1; otherCpi++) { var linkToOther = optimalLinkToCrossovers[otherCpi]; var linkFromOther = linkToOther.PriorIndex < 0 ? new PathLink { PriorIndex = linkToOther.PriorIndex, TotalCost = linkToOther.TotalCost } : new PathLink { PriorIndex = optimalLinkToWaypointsByCrossoverPointIndex[otherCpi][linkToOther.PriorIndex].PriorIndex, TotalCost = linkToOther.TotalCost }; optimalLinkToOtherCrossoversByCrossoverPointIndex[otherCpi].Add(linkFromOther); } return(true); } }
public void should_map_empty_dictionary() { var sut = new Dictionary <string, string>(); int F(string s) => s.Length; var actual = sut.Map(F); actual.Should().NotBeNull(); actual.Count.Should().Be(0); }
public static MetadataAttribute ToAttribute(string name, Dictionary <string, object> args = null, Attribute attr = null) => new MetadataAttribute { Name = name, Attribute = attr, Args = args?.Map(x => new MetadataPropertyType { Name = x.Key, Value = x.Value?.ToString(), Type = x.Value?.GetType().Name, }) };
public void should_map_dictionary_with_one_element() { var sut = new Dictionary <string, string> { { "test", "test" } }; int f(string s) => string.IsNullOrEmpty(s) ? 0 : s.Length; var actual = sut.Map(f); actual.Count.Should().Be(1); actual["test"].Should().Be(4); }
public void TestDict() { var dict = new Dictionary <string, string> { { "one", "1" }, { "two", "2" }, { "three", "3" } }; var resultDict = dict.Map(x => int.Parse(x)); Assert.AreEqual(1, resultDict["one"]); Assert.AreEqual(3, resultDict["three"]); }
public void Map() { var random = new Random(); var expected = new Dictionary<string, object>(); expected.Add("Id", random.Next()); expected.Add("Stringy", Guid.NewGuid().ToString()); expected.Add("Wee", Guid.NewGuid()); var returned = expected.Map(); Assert.IsNotNull(returned); Assert.AreEqual(expected["Id"], returned.Id); Assert.AreEqual(expected["Stringy"], returned.Stringy); Assert.AreEqual(expected["Wee"], returned.Wee); }
public void TestNextRndChild() { var random = new Random(); var list = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i" }; var counters = new Dictionary <string, int>(); for (int i = 0; i < 10000; i++) { var child = random.NextRndChild(list); counters[child] = counters.GetValueOrDefault(child, 0) + 1; } var relStandardDeviation = counters.Map(x => (double)x.Value).GetRelativeStandardDeviation(); // True randomness should cause all counters to be roughly the same (so RSD should be close to 0): Assert.True(relStandardDeviation < 0.05, "relStandardDeviation=" + relStandardDeviation); }
public void MapDictionaryKTTest() { //Arrange var dict = new Dictionary <string, string> { { "ale", "nacion" }, { "pedro", "obligado" } }; //Act var result = dict.Map(e => $"{e}/sn"); //Assert Assert.Equal( new Dictionary <string, string> { { "ale", "nacion/sn" }, { "pedro", "obligado/sn" } }, actual: result ); }
public void should_map_dictionary_with_integers_to_strings() { var sut = new Dictionary <string, int> { { "test", 0 }, { "test1", 1 }, { "test2", 2 }, }; string F(int n) => n.ToString(); var actual = sut.Map(F); actual.Count.Should().Be(3); actual["test"].Should().Be("0"); actual["test1"].Should().Be("1"); actual["test2"].Should().Be("2"); }
public void TestMapping_ExpectPopulatedObject() { var dictionary = new Dictionary <string, AttributeValue> { { "Property1", new AttributeValue("TEST") }, { "Property2", new AttributeValue { BOOL = true } }, { "Id", new AttributeValue { N = "1" } } }; var entity = dictionary.Map <MockTable>(); Assert.Equal(1, entity.Id); Assert.Equal("TEST", entity.Property1); Assert.True(entity.Property2); }
public void should_map_dictionary_with_elements() { var sut = new Dictionary <string, string> { { "", "" }, { "test", "test" }, { "test2", "test3" }, { "test3", "test3" }, }; int f(string s) => string.IsNullOrEmpty(s) ? 0 : s.Length; var actual = sut.Map(f); actual.Count.Should().Be(4); actual[""].Should().Be(0); actual["test"].Should().Be(4); actual["test2"].Should().Be(5); actual["test3"].Should().Be(5); }
public static void Postfix(ref ushort segment, ushort startNode, ushort endNode, bool __result) { if (!__result || !InSimulationThread()) { return; } Log.Debug($"CreateSegment.Postfix( {startNode}.-{segment}-.{endNode} )\n" + Environment.StackTrace, false); if (MoveMiddleNodePatch.CopyData) { var segmentData = MoveMiddleNodePatch.SegmentData; Log.Debug("Moving middle node: copying data to newly created segment. " + $"newSegmentID={segment} data={segmentData}\n", false); PasteSegment(segmentData, startNode, endNode, targetSegmentID: segment); } else if (SplitSegmentPatch.CopyData) { var segmentData = SplitSegmentPatch.SegmentData; var segmentData2 = SplitSegmentPatch.SegmentData2; var segmentData3 = SplitSegmentPatch.SegmentData3; Log.Debug("Spliting segment: copying data to newly created segment. " + $"newSegmentID={segment} data={segmentData} dat2={segmentData2} dat3={segmentData3}\n", false); var map = new Dictionary <InstanceID, InstanceID>(); map.Map(segmentData, startNode, segment); map.Map(segmentData, endNode, segment); map.Map(segmentData2, startNode, segment); map.Map(segmentData2, endNode, segment); map.Map(segmentData3, startNode, segment); map.Map(segmentData3, endNode, segment); PasteSegment(segmentData, startNode, endNode, targetSegmentID: segment); PasteSegment(segmentData2, startNode, endNode, targetSegmentID: segment); PasteSegment(segmentData3, startNode, endNode, targetSegmentID: segment); } else if (ReleaseSegmentImplementationPatch.UpgradingSegmentData != null) { if (!ReleaseSegmentImplementationPatch.m_upgrading) { Log.Error("Unexpected UpgradingSegmentData != null but m_upgrading == false "); } else { var segmentData = ReleaseSegmentImplementationPatch.UpgradingSegmentData; PasteSegment(segmentData, startNode, endNode, targetSegmentID: segment); } ReleaseSegmentImplementationPatch.UpgradingSegmentData = null; // consume } }
public void Should_MapAsExpected_When_FunctionChangesValueType() { var originalSet = new Dictionary <int, int> { [1] = 1, [2] = 2, [3] = 3 }; var expectedResult = new Dictionary <int, string> { [1] = 1.ToString(CultureInfo.InvariantCulture), [2] = 2.ToString(CultureInfo.InvariantCulture), [3] = 3.ToString(CultureInfo.InvariantCulture) }; var result = originalSet.Map( k => k, v => v.ToString(CultureInfo.InvariantCulture)); result.Should().BeEquivalentTo(expectedResult); }
public static void Main(string[] args) { Func <int, double> someFunc = x => x + 1.5; var someSet = new HashSet <int>() { 1, 2, 3, 4, 5 }; var newSet = someSet.Map(someFunc); newSet.ToList().ForEach(x => Console.WriteLine(x)); Console.WriteLine("-------------------"); var someDict = new Dictionary <string, int>(); someDict.Add("key1", 1); someDict.Add("key2", 2); someDict.Add("key3", 3); var newDict = someDict.Map(someFunc); newDict.Values.ToList().ForEach(x => Console.WriteLine(x)); }
public void MapDictionary() { var random = new Random(); var expected = new FillObject() { Id = random.Next(), Band = Guid.NewGuid().ToString(), Song = Guid.NewGuid(), Ecode = Encoding.BigEndianUnicode, NullableByte = null, NullableEnum = null, SuperEnum = HappyLand.MarioLand, TheGuid = null, }; var dic = new Dictionary<string, object>(); dic.Add("Id", expected.Id); dic.Add("Band", expected.Band); dic.Add("Song", expected.Song); dic.Add("Ecode", expected.Ecode); dic.Add("NullableByte", expected.NullableByte); dic.Add("NullableEnum", expected.NullableEnum); dic.Add("SuperEnum", expected.SuperEnum); dic.Add("TheGuid", expected.TheGuid); var returned = dic.Map<FillObject>(); Assert.IsNotNull(returned); Assert.AreEqual(expected.Id, returned.Id); Assert.AreEqual(expected.Band, returned.Band); Assert.AreEqual(expected.Song, returned.Song); Assert.AreEqual(expected.Ecode, returned.Ecode); Assert.AreEqual(expected.NullableByte, returned.NullableByte); Assert.AreEqual(expected.SuperEnum, returned.SuperEnum); Assert.AreEqual(expected.NullableEnum, returned.NullableEnum); Assert.AreEqual(expected.TheGuid, returned.TheGuid); }
public List <PostmanRequest> GetRequests(Postman request, string parentId, IEnumerable <Operation> operations) { var ret = new List <PostmanRequest>(); var feature = HostContext.GetPlugin <PostmanFeature>(); var headers = feature.Headers ?? ("Accept: " + MimeTypes.Json); var httpRes = Response as IHttpResponse; if (httpRes != null) { if (request.ssopt != null || request.sspid != null || request.ssid != null) { if (feature.EnableSessionExport != true) { throw new ArgumentException("PostmanFeature.EnableSessionExport is not enabled"); } } if (request.ssopt != null) { Request.AddSessionOptions(request.ssopt); } if (request.sspid != null) { httpRes.Cookies.AddPermanentCookie(SessionFeature.PermanentSessionId, request.sspid); } if (request.ssid != null) { httpRes.Cookies.AddSessionCookie(SessionFeature.SessionId, request.ssid, (HostContext.Config.OnlySendSessionCookiesSecurely && Request.IsSecureConnection)); } } foreach (var op in operations) { if (!HostContext.Metadata.IsVisible(base.Request, op)) { continue; } var allVerbs = op.Actions.Concat( op.Routes.SelectMany(x => x.Verbs)) .SelectMany(x => x == ActionContext.AnyAction ? feature.DefaultVerbsForAny : new List <string> { x }) .ToHashSet(); var propertyTypes = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); op.RequestType.GetSerializableFields() .Each(x => propertyTypes[x.Name] = x.FieldType.AsFriendlyName(feature)); op.RequestType.GetSerializableProperties() .Each(x => propertyTypes[x.Name] = x.PropertyType.AsFriendlyName(feature)); foreach (var route in op.Routes) { var routeVerbs = route.Verbs.Contains(ActionContext.AnyAction) ? feature.DefaultVerbsForAny.ToArray() : route.Verbs; var restRoute = route.ToRestRoute(); foreach (var verb in routeVerbs) { allVerbs.Remove(verb); //exclude handled verbs var routeData = restRoute.QueryStringVariables .Map(x => new PostmanData { key = x, value = "", type = "text", }) .ApplyPropertyTypes(propertyTypes); ret.Add(new PostmanRequest { collectionId = parentId, id = SessionExtensions.CreateRandomSessionId(), method = verb, url = Request.GetBaseUrl().CombineWith(restRoute.Path.ToPostmanPathVariables()), name = GetName(feature, request, op.RequestType, restRoute.Path), description = op.RequestType.GetDescription(), pathVariables = !verb.HasRequestBody() ? restRoute.Variables.Concat(routeData.Select(x => x.key)) .ApplyPropertyTypes(propertyTypes) : null, data = verb.HasRequestBody() ? routeData : null, dataMode = "params", headers = headers, version = 2, time = DateTime.UtcNow.ToUnixTimeMs(), }); } } var emptyRequest = op.RequestType.CreateInstance(); var virtualPath = emptyRequest.ToReplyUrlOnly(); var requestParams = propertyTypes .Map(x => new PostmanData { key = x.Key, value = x.Value, type = "text", }); ret.AddRange(allVerbs.Select(verb => new PostmanRequest { collectionId = parentId, id = SessionExtensions.CreateRandomSessionId(), method = verb, url = Request.GetBaseUrl().CombineWith(virtualPath), pathVariables = !verb.HasRequestBody() ? requestParams.Select(x => x.key) .ApplyPropertyTypes(propertyTypes) : null, name = GetName(feature, request, op.RequestType, virtualPath), description = op.RequestType.GetDescription(), data = verb.HasRequestBody() ? requestParams : null, dataMode = "params", headers = headers, version = 2, time = DateTime.UtcNow.ToUnixTimeMs(), })); } return(ret); }
static void ProcessDirectory(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, List<string> autoGeneratedComponents, XElement parent) { XElement dirItem = AddDir(parent, wDir); if (wDir.Files.Count() == 0 && wDir.Shortcuts.Count() == 0 && wDir.Dirs.Count() == 0 && wDir.Permissions.Count() == 0) { var existingCompElement = dirItem.Elements("Component"); if (existingCompElement.Count() == 0) { string compId = wDir.Id + ".EmptyDirectory"; if (wDir.Feature != null) { featureComponents.Map(wDir.Feature, compId); } else { defaultFeatureComponents.Add(compId); } dirItem.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); } //insert MergeModules ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents); foreach (Dir subDir in wDir.Dirs) ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem); return; } if (wDir.Feature != null) { string compId = "Component." + wDir.Id; featureComponents.Map(wDir.Feature, compId); dirItem.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); } #region Process Files //insert files in the last leaf directory node foreach (File wFile in wDir.Files) { string fileId = wFile.Id; string compId = "Component." + wFile.Id; if (wFile.Feature != null) { featureComponents.Map(wFile.Feature, compId); } else { defaultFeatureComponents.Add(compId); } XElement comp = dirItem.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); if (wFile.Condition != null) comp.AddElement( new XElement("Condition", new XCData(wFile.Condition.ToCData())) .AddAttributes(wFile.Condition.Attributes)); XElement file = comp.AddElement( new XElement("File", new XAttribute("Id", fileId), new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name))) .AddAttributes(wFile.Attributes)); if (wFile.ServiceInstaller != null) comp.Add(wFile.ServiceInstaller.ToXml(wProject)); if (wFile is Assembly && (wFile as Assembly).RegisterInGAC) { file.Add(new XAttribute("KeyPath", "yes"), new XAttribute("Assembly", ".net"), new XAttribute("AssemblyManifest", fileId), new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString())); } //insert file associations foreach (FileAssociation wFileAssociation in wFile.Associations) { XElement progId; comp.Add(progId = new XElement("ProgId", new XAttribute("Id", wFileAssociation.Extension + ".file"), new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()), new XAttribute("Description", wFileAssociation.Description), new XElement("Extension", new XAttribute("Id", wFileAssociation.Extension), new XAttribute("ContentType", wFileAssociation.ContentType), new XElement("Verb", wFileAssociation.Advertise ? new XAttribute("Sequence", wFileAssociation.SequenceNo) : new XAttribute("TargetFile", fileId), new XAttribute("Id", wFileAssociation.Command), new XAttribute("Command", wFileAssociation.Command), new XAttribute("Argument", wFileAssociation.Arguments))))); if (wFileAssociation.Icon != null) { progId.Add( new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId), new XAttribute("IconIndex", wFileAssociation.IconIndex)); } } //insert file owned shortcuts foreach (Shortcut wShortcut in wFile.Shortcuts) { string locationDirId; if (wShortcut.Location.IsEmpty()) { locationDirId = wDir.Id; } else { Dir locationDir = wProject.FindDir(wShortcut.Location); if (locationDir != null) { locationDirId = locationDir.Id; } else { if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location)) autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature); locationDirId = wShortcut.Location.Expand(); } } var shortcutElement = new XElement("Shortcut", new XAttribute("Id", "Shortcut." + wFile.Id + "." + wShortcut.Id), new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : locationDirId), new XAttribute("Directory", locationDirId), new XAttribute("Name", wShortcut.Name.IsNullOrEmpty() ? IO.Path.GetFileNameWithoutExtension(wFile.Name) : wShortcut.Name + ".lnk")); wShortcut.EmitAttributes(shortcutElement); file.Add(shortcutElement); } //insert file related IIS virtual directories InsertIISElements(dirItem, comp, wFile.IISVirtualDirs, wProject); //insert file owned permissions ProcessFilePermissions(wProject, wFile, file); } #endregion #region Process Shorcuts //insert directory owned shortcuts foreach (Shortcut wShortcut in wDir.Shortcuts) { string compId = wShortcut.Id; if (wShortcut.Feature != null) { if (!featureComponents.ContainsKey(wShortcut.Feature)) featureComponents[wShortcut.Feature] = new List<string>(); featureComponents[wShortcut.Feature].Add(compId); } else { defaultFeatureComponents.Add(compId); } XElement comp = dirItem.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); if (wShortcut.Condition != null) comp.AddElement( new XElement("Condition", wShortcut.Condition.ToCData()) .AddAttributes(wShortcut.Condition.Attributes)); XElement sc; sc = comp.AddElement( new XElement("Shortcut", new XAttribute("Id", wDir.Id + "." + wShortcut.Id), //new XAttribute("Directory", wDir.Id), //not needed for Wix# as this attributed is required only if the shortcut is not nested under a Component element. new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : GetShortcutWorkingDirectopry(wShortcut.Target)), new XAttribute("Target", wShortcut.Target), new XAttribute("Arguments", wShortcut.Arguments), new XAttribute("Name", wShortcut.Name + ".lnk"))); wShortcut.EmitAttributes(sc); } #endregion //insert MergeModules ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents); ProcessDirPermissions(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem); foreach (Dir subDir in wDir.Dirs) ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem); }
public List<PostmanRequest> GetRequests(Postman request, string parentId, IEnumerable<Operation> operations) { var ret = new List<PostmanRequest>(); var feature = HostContext.GetPlugin<PostmanFeature>(); var headers = feature.Headers ?? ("Accept: " + MimeTypes.Json); var httpRes = Response as IHttpResponse; if (httpRes != null) { if (request.ssopt != null || request.sspid != null || request.ssid != null) { if (feature.EnableSessionExport != true) { throw new ArgumentException("PostmanFeature.EnableSessionExport is not enabled"); } } if (request.ssopt != null) { Request.AddSessionOptions(request.ssopt); } if (request.sspid != null) { httpRes.Cookies.AddPermanentCookie(SessionFeature.PermanentSessionId, request.sspid); } if (request.ssid != null) { httpRes.Cookies.AddSessionCookie(SessionFeature.SessionId, request.ssid, (HostContext.Config.OnlySendSessionCookiesSecurely && Request.IsSecureConnection)); } } foreach (var op in operations) { if (!HostContext.Metadata.IsVisible(base.Request, op)) continue; var allVerbs = op.Actions.Concat( op.Routes.SelectMany(x => x.Verbs)) .SelectMany(x => x == ActionContext.AnyAction ? feature.DefaultVerbsForAny : new List<string> { x }) .ToHashSet(); var propertyTypes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); op.RequestType.GetSerializableFields() .Each(x => propertyTypes[x.Name] = x.FieldType.AsFriendlyName(feature)); op.RequestType.GetSerializableProperties() .Each(x => propertyTypes[x.Name] = x.PropertyType.AsFriendlyName(feature)); foreach (var route in op.Routes) { var routeVerbs = route.Verbs.Contains(ActionContext.AnyAction) ? feature.DefaultVerbsForAny.ToArray() : route.Verbs; var restRoute = route.ToRestRoute(); foreach (var verb in routeVerbs) { allVerbs.Remove(verb); //exclude handled verbs var routeData = restRoute.QueryStringVariables .Map(x => new PostmanData { key = x, value = "", type = "text", }) .ApplyPropertyTypes(propertyTypes); ret.Add(new PostmanRequest { collectionId = parentId, id = SessionExtensions.CreateRandomSessionId(), method = verb, url = Request.GetBaseUrl().CombineWith(restRoute.Path.ToPostmanPathVariables()), name = GetName(feature, request, op.RequestType, restRoute.Path), description = op.RequestType.GetDescription(), pathVariables = !verb.HasRequestBody() ? restRoute.Variables.Concat(routeData.Select(x => x.key)) .ApplyPropertyTypes(propertyTypes) : null, data = verb.HasRequestBody() ? routeData : null, dataMode = "params", headers = headers, version = 2, time = DateTime.UtcNow.ToUnixTimeMs(), }); } } var emptyRequest = op.RequestType.CreateInstance(); var virtualPath = emptyRequest.ToReplyUrlOnly(); var requestParams = propertyTypes .Map(x => new PostmanData { key = x.Key, value = x.Value, type = "text", }); ret.AddRange(allVerbs.Select(verb => new PostmanRequest { collectionId = parentId, id = SessionExtensions.CreateRandomSessionId(), method = verb, url = Request.GetBaseUrl().CombineWith(virtualPath), pathVariables = !verb.HasRequestBody() ? requestParams.Select(x => x.key) .ApplyPropertyTypes(propertyTypes) : null, name = GetName(feature, request, op.RequestType, virtualPath), description = op.RequestType.GetDescription(), data = verb.HasRequestBody() ? requestParams : null, dataMode = "params", headers = headers, version = 2, time = DateTime.UtcNow.ToUnixTimeMs(), })); } return ret; }
public TerrainOverlayNetwork CompileTerrainOverlayNetwork(double agentRadius) { if (terrainOverlayNetworkCache.TryGetValue(agentRadius, out var existingTerrainOverlayNetwork)) { return(existingTerrainOverlayNetwork); } // Console.WriteLine($"Compiling Terrain Overlay Network for Agent Radius {agentRadius}."); //---------------------------------------------------------------------------------------- // Sector Node Description => Default Local Geometry View //---------------------------------------------------------------------------------------- var renderedLocalGeometryViewBySectorNodeDescription = localGeometryViewManagerBySectorNodeDescription.Map( (k, v) => v.GetErodedView(agentRadius * k.WorldToLocalScalingFactor)); var defaultLocalGeometryViewBySectorNodeDescription = renderedLocalGeometryViewBySectorNodeDescription.Map( (k, v) => true || v.IsPunchedLandEvaluated ? v : v.Preview); var landPolyNodesByDefaultLocalGeometryView = defaultLocalGeometryViewBySectorNodeDescription.Values.Distinct().ToDictionary( lgv => lgv, lgv => lgv.PunchedLand.GetLandNodes()); var terrainNodesBySectorNodeDescription = defaultLocalGeometryViewBySectorNodeDescription.Map( (k, v) => landPolyNodesByDefaultLocalGeometryView[v].Map(pn => new TerrainOverlayNetworkNode(k, v, pn))); var terrainNodesBySectorNodeDescriptionAndPolyNode = terrainNodesBySectorNodeDescription.Values.SelectMany(tns => tns).ToDictionary( tn => (tn.SectorNodeDescription, tn.LandPolyNode)); //---------------------------------------------------------------------------------------- // Edge Lookups //---------------------------------------------------------------------------------------- var edgesBySource = edgeDescriptions.ToLookup(ed => ed.Source); var edgesByDestination = edgeDescriptions.ToLookup(ed => ed.Destination); var edgesByEndpoints = MultiValueDictionary <SectorNodeDescription, SectorEdgeDescription> .Create(() => new HashSet <SectorEdgeDescription>()); foreach (var(k, edges) in edgesBySource) { foreach (var edge in edges) { edgesByEndpoints.Add(k, edge); } } foreach (var(k, edges) in edgesByDestination) { foreach (var edge in edges) { edgesByEndpoints.Add(k, edge); } } //---------------------------------------------------------------------------------------- // Build and Initialize Terrain Overlay Network //---------------------------------------------------------------------------------------- var terrainOverlayNetwork = new TerrainOverlayNetwork( agentRadius, defaultLocalGeometryViewBySectorNodeDescription, terrainNodesBySectorNodeDescription, landPolyNodesByDefaultLocalGeometryView, terrainNodesBySectorNodeDescriptionAndPolyNode, edgeDescriptions, edgesBySource, edgesByDestination, edgesByEndpoints); terrainOverlayNetwork.Initialize(); return(terrainOverlayNetworkCache[agentRadius] = terrainOverlayNetwork); }
public void MapWithDictionary() { var dict = new Dictionary<string, object> { { "Id", null }, { "Foo", "Bar" } }; var bar = dict.Map(self => { var dictMapper = Fn.Func((string name) => self[name] ?? ""); return new { Id = dictMapper("Id"), Foo = dictMapper("Foo") }; }); Assert.AreEqual("", bar.Id); Assert.AreEqual("Bar", bar.Foo); }
public static string AsJiraUserToVsts(this string user) { return(Users.Map(user)); }
public void DictionaryBaseTest() { var map = MapFactory.CreateMapRule<InnType, OutType2>(); //Adding mapping rule for field that does not match on name. map.GetRule<InnType, OutType2>() .Add(type => type.DesimalValue, type => type.DesimalValue1, BasicTypes.Convertable); var target = new Dictionary<int, InnType> { { 1, new InnType { DateTimeValue = DateTime.Now, MyInts = new List<int>(), StringValue = "test1", DesimalValue = 1 } }, { 2, new InnType { DateTimeValue = DateTime.Now, MyInts = new List<int>(), StringValue = "test1", DesimalValue = 2 } } }; var result = target.Map<int, InnType>().To<string, OutType2>(map); Assert.AreEqual(2, result.Count); }
public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) { Dictionary <String, String> d = new Dictionary <string, string>(); String s = null; foreach (var item in this.DataProviders) { var ds = this.GetDataSource(actionContext, item); foreach (var key in ds.Keys) { if (d.ContainsKey(key) == true) { continue; } d[key] = ds[key]; } if (ds.ContainsKey(Descriptor.ParameterName) == true) { s = ds[Descriptor.ParameterName]; break; } } if (this.IsUnifyLineFeed == true) { s = s.UnifyLineFeed(); } var pValue = GetValue(Descriptor.ParameterType, s); if (pValue == null && Descriptor.DefaultValue != null) { pValue = Descriptor.DefaultValue; } if (pValue == null && Descriptor.ParameterType.IsClass) { try { var o = Activator.CreateInstance(Descriptor.ParameterType); d.Map(o); pValue = o; } catch { } } if (pValue == null) { if (Descriptor.ParameterType.IsInheritanceFrom(typeof(Nullable <>)) || Descriptor.ParameterType.IsClass) { this.SetValue(actionContext, pValue); } } else { this.SetValue(actionContext, pValue); } TaskCompletionSource <Object> tcs = new TaskCompletionSource <Object>(); tcs.SetResult(null); return(tcs.Task); }
private static Object GetValue(Type type, String value) { Object pValue = null; var s = value; if (s == null) { return(pValue); } if (type == typeof(String)) { pValue = s; } else if (type == typeof(Boolean) || type == typeof(Boolean?)) { pValue = s.ToBoolean(); } else if (type == typeof(Guid) || type == typeof(Guid?)) { pValue = s.ToGuid(); } else if (type == typeof(Int16) || type == typeof(Int16?)) { pValue = s.ToInt16(); } else if (type == typeof(Int32) || type == typeof(Int32?)) { pValue = s.ToInt32(); } else if (type == typeof(Int64) || type == typeof(Int64?)) { pValue = s.ToInt64(); } else if (type == typeof(UInt16) || type == typeof(UInt16?)) { pValue = s.ToUInt16(); } else if (type == typeof(UInt32) || type == typeof(UInt32?)) { pValue = s.ToUInt32(); } else if (type == typeof(UInt64) || type == typeof(UInt64?)) { pValue = s.ToUInt64(); } else if (type == typeof(Byte) || type == typeof(Byte?)) { pValue = s.ToByte(); } else if (type == typeof(SByte) || type == typeof(SByte?)) { pValue = s.ToSByte(); } else if (type == typeof(Single) || type == typeof(Single?)) { pValue = s.ToSingle(); } else if (type == typeof(Double) || type == typeof(Double?)) { pValue = s.ToDouble(); } else if (type == typeof(Decimal) || type == typeof(Decimal?)) { pValue = s.ToDecimal(); } else if (type == typeof(DateTime) || type == typeof(DateTime?)) { pValue = s.ToDateTime(); } else if (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?)) { pValue = s.ToDateTimeOffset(); } else if (type.IsEnum) { pValue = s.ToEnum(type); } else if (type.IsInheritanceFrom(typeof(Nullable <>)) == true) { var tp = type.GetGenericArguments()[0]; if (tp.IsEnum) { pValue = s.ToEnum(tp); } } else if (type.IsInheritanceFrom(typeof(IEnumerable <>))) { if (s.Trim().StartsWith("[")) { var oo = JsonConvert.DeserializeObject(s.Trim()); if (oo is JArray) { Type tp = type.GetGenericArguments()[0]; var ltp = typeof(List <>).MakeGenericType(tp); var md = ltp.GetMethod("Add"); var pp = Activator.CreateInstance(ltp); foreach (var o in oo as JArray) { if (o is JObject) { var dd = new Dictionary <String, String>(); var jo = o as JObject; foreach (var property in jo.Properties()) { dd[property.Name] = jo[property.Name].ToString(); } var o1 = Activator.CreateInstance(tp); dd.Map(o1); md.Invoke(pp, new Object[] { o1 }); } else if (o is JToken) { var o1 = GetValue(tp, o.ToString()); md.Invoke(pp, new Object[] { o1 }); } } pValue = pp; } } } else if (type.IsPrimitive || type.IsValueType) { try { pValue = Convert.ChangeType(s, type); } catch { } } return(pValue); }
public List <PostmanRequest> GetRequests(Postman request, string parentId, IEnumerable <Operation> operations) { var ret = new List <PostmanRequest>(); var feature = HostContext.GetPlugin <PostmanFeature>(); var headers = feature.Headers ?? ("Accept: " + MimeTypes.Json); if (Response is IHttpResponse httpRes) { if (request.ssopt != null || request.sspid != null || request.ssid != null) { if (feature.EnableSessionExport != true) { throw new ArgumentException("PostmanFeature.EnableSessionExport is not enabled"); } } if (request.ssopt != null) { Request.AddSessionOptions(request.ssopt); } if (request.sspid != null) { httpRes.Cookies.AddPermanentCookie(SessionFeature.PermanentSessionId, request.sspid); } if (request.ssid != null) { httpRes.Cookies.AddSessionCookie(SessionFeature.SessionId, request.ssid, (HostContext.Config.UseSecureCookies && Request.IsSecureConnection)); } } foreach (var op in operations) { Uri url = null; if (!HostContext.Metadata.IsVisible(base.Request, op)) { continue; } var allVerbs = new HashSet <string>(op.Actions.Concat( op.Routes.SelectMany(x => x.Verbs)) .SelectMany(x => x == ActionContext.AnyAction ? feature.DefaultVerbsForAny : new List <string> { x })); var propertyTypes = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); op.RequestType.GetSerializableFields() .Each(x => propertyTypes[x.Name] = x.FieldType.AsFriendlyName(feature)); op.RequestType.GetSerializableProperties() .Each(x => propertyTypes[x.Name] = x.PropertyType.AsFriendlyName(feature)); foreach (var route in op.Routes) { var routeVerbs = route.Verbs.Contains(ActionContext.AnyAction) ? feature.DefaultVerbsForAny.ToArray() : route.Verbs; var restRoute = route.ToRestRoute(); foreach (var verb in routeVerbs) { allVerbs.Remove(verb); //exclude handled verbs var routeData = restRoute.QueryStringVariables .Map(x => new PostmanData { key = x, value = "", type = "text", }) .ApplyPropertyTypes(propertyTypes); url = new Uri(Request.GetBaseUrl().CombineWith(restRoute.Path.ToPostmanPathVariables())); ret.Add(new PostmanRequest { request = new PostmanRequestDetails { url = new PostmanRequestUrl { raw = url.OriginalString, host = url.Host, port = url.Port.ToString(), protocol = url.Scheme, path = url.LocalPath.SplitPaths(), query = !HttpUtils.HasRequestBody(verb) ? routeData.Select(x => x.key) .ApplyPropertyTypes(propertyTypes) .Map(x => new PostmanRequestKeyValue { key = x.Key, value = x.Value }) : null, variable = restRoute.Variables.Any() ? restRoute.Variables.Map(x => new PostmanRequestKeyValue { key = x }) : null }, method = verb, body = new PostmanRequestBody { formdata = HttpUtils.HasRequestBody(verb) ? routeData : null, }, header = headers, }, name = GetName(feature, request, op.RequestType, restRoute.Path), }); } } var emptyRequest = op.RequestType.CreateInstance(); var virtualPath = emptyRequest.ToReplyUrlOnly(); var requestParams = propertyTypes .Map(x => new PostmanData { key = x.Key, value = x.Value, type = "text", }); url = new Uri(Request.GetBaseUrl().CombineWith(virtualPath)); ret.AddRange(allVerbs.Select(verb => new PostmanRequest { request = new PostmanRequestDetails { url = new PostmanRequestUrl { raw = url.OriginalString, host = url.Host, port = url.Port.ToString(), protocol = url.Scheme, path = url.LocalPath.SplitPaths(), query = !HttpUtils.HasRequestBody(verb) ? requestParams.Select(x => x.key) .Where(x => !x.StartsWith(":")) .ApplyPropertyTypes(propertyTypes) .Map(x => new PostmanRequestKeyValue { key = x.Key, value = x.Value }) : null, variable = url.Segments.Any(x => x.StartsWith(":")) ? url.Segments.Where(x => x.StartsWith(":")) .Map(x => new PostmanRequestKeyValue { key = x.Replace(":", ""), value = "" }) : null }, method = verb, body = new PostmanRequestBody { formdata = HttpUtils.HasRequestBody(verb) ? requestParams : null, }, header = headers, }, name = GetName(feature, request, op.RequestType, virtualPath), })); } return(ret); }
public static string ToVsts(this IssuePriority issuePriority) { return(Priority.Map(issuePriority.ToString())); }
public static string ToVsts(this IssueType issueType) { return(IssueType.Map(issueType.ToString())); }
static void ProcessDirectoryFiles(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, XElement dirItem) { //insert files in the last leaf directory node foreach (File wFile in wDir.Files) { string fileId = wFile.Id; string compId = "Component." + wFile.Id; if (wFile.Feature != null) { featureComponents.Map(wFile.Feature, compId); } else { defaultFeatureComponents.Add(compId); } XElement comp = dirItem.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); if (wFile.Condition != null) comp.AddElement( new XElement("Condition", new XCData(wFile.Condition.ToCData())) .AddAttributes(wFile.Condition.Attributes)); XElement file = comp.AddElement( new XElement("File", new XAttribute("Id", fileId), new XAttribute("Source", Utils.PathCombine(wProject.SourceBaseDir, wFile.Name))) .AddAttributes(wFile.Attributes)); if (wFile.ServiceInstaller != null) comp.Add(wFile.ServiceInstaller.ToXml(wProject)); if (wFile is Assembly && (wFile as Assembly).RegisterInGAC) { file.Add(new XAttribute("KeyPath", "yes"), new XAttribute("Assembly", ".net"), new XAttribute("AssemblyManifest", fileId), new XAttribute("ProcessorArchitecture", ((Assembly)wFile).ProcessorArchitecture.ToString())); } wFile.DriverInstaller.Compile(wProject, comp); //insert file associations foreach (FileAssociation wFileAssociation in wFile.Associations) { XElement progId; comp.Add(progId = new XElement("ProgId", new XAttribute("Id", wFileAssociation.Extension + ".file"), new XAttribute("Advertise", wFileAssociation.Advertise.ToYesNo()), new XAttribute("Description", wFileAssociation.Description), new XElement("Extension", new XAttribute("Id", wFileAssociation.Extension), new XAttribute("ContentType", wFileAssociation.ContentType), new XElement("Verb", wFileAssociation.Advertise ? new XAttribute("Sequence", wFileAssociation.SequenceNo) : new XAttribute("TargetFile", fileId), new XAttribute("Id", wFileAssociation.Command), new XAttribute("Command", wFileAssociation.Command), new XAttribute("Argument", wFileAssociation.Arguments))))); if (wFileAssociation.Icon != null) { progId.Add( new XAttribute("Icon", wFileAssociation.Icon != "" ? wFileAssociation.Icon : fileId), new XAttribute("IconIndex", wFileAssociation.IconIndex)); } } //insert file owned shortcuts foreach (Shortcut wShortcut in wFile.Shortcuts) { string locationDirId; if (wShortcut.Location.IsEmpty()) { locationDirId = wDir.Id; } else { Dir locationDir = wProject.FindDir(wShortcut.Location); if (locationDir != null) { locationDirId = locationDir.Id; } else { if (!autogeneratedShortcutLocations.ContainsKey(wShortcut.Location)) autogeneratedShortcutLocations.Add(wShortcut.Location, wShortcut.Feature); locationDirId = wShortcut.Location.Expand(); } } var shortcutElement = new XElement("Shortcut", new XAttribute("Id", "Shortcut." + wFile.Id + "." + wShortcut.Id), new XAttribute("WorkingDirectory", !wShortcut.WorkingDirectory.IsEmpty() ? wShortcut.WorkingDirectory.Expand() : locationDirId), new XAttribute("Directory", locationDirId), new XAttribute("Name", wShortcut.Name.IsNullOrEmpty() ? IO.Path.GetFileNameWithoutExtension(wFile.Name) : wShortcut.Name + ".lnk")); wShortcut.EmitAttributes(shortcutElement); file.Add(shortcutElement); } //insert file related IIS virtual directories InsertIISElements(dirItem, comp, wFile.IISVirtualDirs, wProject); //insert file owned permissions ProcessFilePermissions(wProject, wFile, file); } }
static void ProcessDirectory(Dir wDir, Project wProject, Dictionary<Feature, List<string>> featureComponents, List<string> defaultFeatureComponents, List<string> autoGeneratedComponents, XElement parent) { XElement dirItem = AddDir(parent, wDir); bool isEmptyDir = wDir.Files.None() && wDir.Shortcuts.None() && wDir.Dirs.None() && wDir.MergeModules.None() && wDir.Permissions.None() && wDir.ODBCDataSources.None(); if (isEmptyDir) { var existingCompElement = dirItem.Elements("Component"); if (existingCompElement.Count() == 0) { string compId = wDir.Id + ".EmptyDirectory"; if (wDir.Feature != null) { featureComponents.Map(wDir.Feature, compId); } else { defaultFeatureComponents.Add(compId); } dirItem.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); } } else { if (wDir.Feature != null) { string compId = "Component." + wDir.Id; featureComponents.Map(wDir.Feature, compId); dirItem.AddElement( new XElement("Component", new XAttribute("Id", compId), new XAttribute("Guid", WixGuid.NewGuid(compId)))); } ProcessDirectoryFiles(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem); ProcessDirectoryShortcuts(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem); ProcessOdbcSources(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem); ProcessMergeModules(wDir, dirItem, featureComponents, defaultFeatureComponents); ProcessDirPermissions(wDir, wProject, featureComponents, defaultFeatureComponents, dirItem); foreach (Dir subDir in wDir.Dirs) ProcessDirectory(subDir, wProject, featureComponents, defaultFeatureComponents, autoGeneratedComponents, dirItem); } }
public void RequestTestNulls() { var Request = new Dictionary<string, object> { { "id", 12 }, { "foo", null } }; var request = Request.Map(self => new { id = self["id"] ?? 0, foo = self["foo"] ?? "" }); Assert.AreEqual(12, request.id); Assert.AreEqual("", request.foo); }
/// <summary> /// VSTS: New, Active, Closed, Removed, Resolved. /// JIRA: To Do, In Progress, Dev Complete, In Testing, Done. /// </summary> public static string ToVsts(this IssueStatus issueStatus) { return(Status.Map(issueStatus.ToString())); }
string render(Dictionary <string, object> links) => $@"<ul> {links.Map(entry => $"<li><a href='{entry.Key}'>{entry.Value}</a></li>\n").Join("")} </ul>";
public override Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken) { Dictionary <String, String> d = new Dictionary <string, string>(); String s = null; foreach (var item in this.DataProviders) { var ds = this.GetDataSource(actionContext, item); foreach (var key in ds.Keys) { if (d.ContainsKey(key) == true) { continue; } d[key] = ds[key]; } if (ds.ContainsKey(Descriptor.ParameterName) == true) { s = ds[Descriptor.ParameterName]; break; } } Object pValue = null; if (Descriptor.ParameterType == typeof(String)) { pValue = s; } else if (Descriptor.ParameterType == typeof(Boolean) || Descriptor.ParameterType == typeof(Boolean?)) { pValue = s.ToBoolean(); } else if (Descriptor.ParameterType == typeof(Guid) || Descriptor.ParameterType == typeof(Guid?)) { pValue = s.ToGuid(); } else if (Descriptor.ParameterType == typeof(Int16) || Descriptor.ParameterType == typeof(Int16?)) { pValue = s.ToInt16(); } else if (Descriptor.ParameterType == typeof(Int32) || Descriptor.ParameterType == typeof(Int32?)) { pValue = s.ToInt32(); } else if (Descriptor.ParameterType == typeof(Int64) || Descriptor.ParameterType == typeof(Int64?)) { pValue = s.ToInt64(); } else if (Descriptor.ParameterType == typeof(UInt16) || Descriptor.ParameterType == typeof(UInt16?)) { pValue = s.ToUInt16(); } else if (Descriptor.ParameterType == typeof(UInt32) || Descriptor.ParameterType == typeof(UInt32?)) { pValue = s.ToUInt32(); } else if (Descriptor.ParameterType == typeof(UInt64) || Descriptor.ParameterType == typeof(UInt64?)) { pValue = s.ToUInt64(); } else if (Descriptor.ParameterType == typeof(Byte) || Descriptor.ParameterType == typeof(Byte?)) { pValue = s.ToByte(); } else if (Descriptor.ParameterType == typeof(SByte) || Descriptor.ParameterType == typeof(SByte?)) { pValue = s.ToSByte(); } else if (Descriptor.ParameterType == typeof(Single) || Descriptor.ParameterType == typeof(Single?)) { pValue = s.ToSingle(); } else if (Descriptor.ParameterType == typeof(Double) || Descriptor.ParameterType == typeof(Double?)) { pValue = s.ToDouble(); } else if (Descriptor.ParameterType == typeof(Decimal) || Descriptor.ParameterType == typeof(Decimal?)) { pValue = s.ToDecimal(); } else if (Descriptor.ParameterType == typeof(DateTime) || Descriptor.ParameterType == typeof(DateTime?)) { pValue = s.ToDateTime(); } else if (Descriptor.ParameterType == typeof(DateTimeOffset) || Descriptor.ParameterType == typeof(DateTimeOffset?)) { pValue = s.ToDateTimeOffset(); } else if (Descriptor.ParameterType.IsEnum) { pValue = s.ToEnum(Descriptor.ParameterType); } else if (Descriptor.ParameterType.IsInheritanceFrom(typeof(Nullable <>)) == true) { var tp = Descriptor.ParameterType.GetGenericArguments()[0]; if (tp.IsEnum) { pValue = s.ToEnum(tp); } } else if (Descriptor.ParameterType.IsPrimitive || Descriptor.ParameterType.IsValueType) { try { pValue = Convert.ChangeType(s, Descriptor.ParameterType); } catch { } } else if (Descriptor.ParameterType.IsClass) { try { var o = Activator.CreateInstance(Descriptor.ParameterType); d.Map(o); pValue = o; } catch { } } if (pValue == null && Descriptor.DefaultValue != null) { pValue = Descriptor.DefaultValue; } if (pValue == null) { if (Descriptor.ParameterType.IsInheritanceFrom(typeof(Nullable <>)) || Descriptor.ParameterType.IsClass) { this.SetValue(actionContext, pValue); } } else { this.SetValue(actionContext, pValue); } TaskCompletionSource <Object> tcs = new TaskCompletionSource <Object>(); tcs.SetResult(null); return(tcs.Task); }